/* ZLB Puzzle: Rotemberg pricing  */
/* By Toshihiro OKADA */


//** the time period of the simulated siries: ts=start te=end **
ts=1001; te=1190;


////** Line specification for figures **////////////
lsp =1; /* setting a line specification for figures: 1='- black', 2='-- red', 3=':blue' and 4='-.green' , 5='-.black' */


///***** Choosing a set of parameters (posterior modes): Basic NK, Standard NK, and EPD-NK models *****//  
@#define data_techzero=1 
//* 0: Basic or Standard NK                      *//
//* 1: EPD-NK                                    *// 

//********** Model choice ********* //
@#define tech =1
//* 1: EPD NK                *// 
//* 0: Basic or Standard NK  *//

//**** Shutting down endogenous technology for EPD-NK model ***// 
@#define ashock=1
//* 1: with endogenous tech.     *//
//* 0: without endogenous tech.  *//

//******Zero Lower Band: ZLB (ELB) *******//
@#define ELB=1
//* =1: ZLB is ON  *//
//* =0; ZLB is OFF  *//

//*** Price index *****//
@#define pindex=0
//* pindex==0: no price index  *//
//* pindex==1: with price index *//
//*******************************//

//** Rotemberg (1982) pricing**//
@#define roten =1
rho_rot =0.7218; /* 0.7218 (mode of rho) to set up "rot" value */ 
//***************************//


//*******TFP shock specification ******//
@#define tfp_normal=0
//* 1:normal specification: choose this for appendix figure 19                    //
//* 0:fixed period constant reduction of TFP //
rhou_new=0.92; //** for appendix tebale 19 **// 

////*** Habit & inv adj cost specification *****//  
@#define simple=0
//* =0: With capital, habit and inv adj cost *//
//* =2: With capital & no habit and no inv adj cost *//
//***************************************//





//** length of S( ) variables **//
@#define slong=28

@#define tfplong=28

/////////////////////////////////////////////////////////
//*****Bayesian IRFs: mean, lower & higher bounds ** ////
@#define bayes=1
@#define bayirf=1
//** 0: No baysian IRF & use just mode or mean
// 0: No bayes
// 1: With bayes//////////////////////////
///////////////////////////////////////////

@#define lwrhou=1
//** Not used **//


// **** STD specification **// 
@#define std_spec =0
//* std_spec=0: arbitrary std*//
//* std_spec=1: estimated std *//
//****************************//

//******** Conditional varinace; on-off ****//
@#define cndvar=0
/** cndvar=1: for (theoretical) conditional variance calculation (std=estimated values) **/  
/** cndvar=0: for otherwisee **/
//*******************************************//

@#define fig = 1
@#define fig_series=0
@#define full_fig=0

//****** Mean/Meian choice for IRF & baysian IRF *************//
@#define mean_median=1
//** 1:mean
//** 2:median


//*********************************//
//**** Confidence band ******//
@#define conf_band=0
//** 0: 90% **//
//** 1: 95% **//
//** 2: 1 standard deviation
//*********************************//

//**********************************************//
//************ Loading data ********************//
//**********************************************//

@#if data_techzero==1 

@#if bayes==0
load('subdraws_phi60stv90mm5_mode.mat', 'aa0');
@#endif
@#if bayes==1
load('subdraws_phi60stv90mm5_arrange.mat', 'aa0');
@#endif


@#endif

@#if data_techzero==0

//* Without Indexization *// 

@#if bayes==0
 @#if pindex==0
load('subdraws_BNKphi60stv90m3_mode.mat', 'aa0');
 @#endif


//* With Indexization *// 
 @#if pindex==1
load('subdraws_BNKphi60stv90index_mode.mat', 'aa0');
 @#endif
@#endif

@#if bayes==1
 @#if pindex==0
load('subdraws_BNKphi60stv90m3.mat', 'aa0');
 @#endif


//* With Indexization *// 
 @#if pindex==1
 load('subdraws_BNKphi60stv90index.mat', 'aa0');
 @#endif
@#endif


@#endif


@#define large_sample=0
sim_period=190;
me_std=0.00; 
mee_std=0.0; 
meee_std=0.0;

//**********************************//
//********SETTING SEEDS***********//
//**********************************//


//**** Not used  *****//
dma=1;
dmb=1;
//**********************************************************************//

//****  Not used  *****// 
jrdma=1; /* seed for news shock simulation random numbering*/
jrdmb=1; /* seed for news shock simulation random numbering*/
//**********************************************************************//

//****  Not used *****//
iia=1; /* start of random shock seed # */
iib=1; /* end of random shock seed # */
//**************************************************************//

//**** Bayesian coefficient estimates random shock seeds ***********************//
ja=1;/* start of sub draws random shock seed # */
jb=500;/* end of sub draws random shock seed #  */
//**************************************************************//



alfa_n = 140; /* 425to shut down technology effect */



//** Shock Specification for monte carlo: use this for monte carlo simluations (dshock=0): MAKE ALL SHOCKS on for IRF SIMULATION **//
@#define ushock=1
@#define news=1
@#define dshock=0
@#define cshock=1
@#define hshock=1
@#define ishock=1
@#define fshock=1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//* ushock: ushock=0 shut down technology(u)shocks, 2: news: news=0, shut down  news shock but leave u shocks, cshock: consumption shock, hshock: hour shocks, ishock:interest rate shock *// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



@#define fullshock=3

//***************************************************************//
//**Epected monopoly profit specifications                    **//
//** Choose this by corresponding to fullshock specification ** //
//**************************************************************//
@#define exp_spec=8
//* 8=8 period ahead expected, 12=12 period ahead expected profits, etc *//


ex_time_=8; //* if e8 shock is chosen, chose ex_time_=8 . For a single unrealized news shock IRF *// 
@#define ex_time_periods=8



@#if fullshock==3
 @#define shki =0
 @#define shku =1
 @#define shkue =0
 @#define shkue1 =0
 @#define shkue2 =0
 @#define shkue3 =0
 @#define shkue4 =0
 @#define shkue5 =0
 @#define shkue6 =0
 @#define shkue7 =0
 @#define shkue8 =0
 @#define shkue9 =0
 @#define shkue10 =0 
 @#define shkue11 =0 
 @#define shkue12 =0 
 @#define shkue13 =0 
 @#define shkue14 =0 
 @#define shkue15 =0
 @#define shkue16 =0 
 @#define shkue17 =0 
 @#define shkue18 =0 
 @#define shkue19 =0 
 
 @#define shkuc =0
 @#define shkuh =0
 @#define shkf =0
 @#endif 


//* j= bayesyean coefficients*//
for j=ja:jb

@#if tech==1
 
  @#if ELB==0 

    var 
    @#if tfp_normal==1
    y_g, c_g, tiv_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp,tfpu,u,a, c,k,iv,h,w,r,rr,p,ppai,m,pf,pf_exp,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,pfn,in,lamdan,yg,hg,fpai,mcgap,rd,rdn,an,nf,nfn,pinf,uc,um,uh,tiv, tivn ynobs,mcgape, mc, mcn  mce, fpaie, paie, paiee,ppaie, inftr,  tfpn, tq,tqn, shu, shi, shc, shh, shue1 shue3 shue4 shue8  aa aan sp stk  ;
    @#endif

    @#if tfp_normal==0
      @#if tfplong==28
      tf1, tf2, 
      @#endif
      y_g, c_g, tiv_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp,tfpu,u,a, c,k,iv,h,w,r,rr,p,ppai,m,pf,pf_exp,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,pfn,in,lamdan,yg,hg,fpai,mcgap,rd,rdn,an,nf,nfn,pinf,uc,um,uh,tiv, tivn ynobs,mcgape, mc, mcn  mce, fpaie, paie, paiee,ppaie, inftr,  tfpn, tq,tqn, shu, shi, shc, shh, shue1 shue3 shue4 shue8  aa aan sp stk  ;
    @#endif
  @#endif
  
 @#if ELB==1 
 
  var
  @#if slong==0
  @#endif
  @#if slong==4
  s1, s2, s3, s4
  @#endif
  @#if slong==7
  s1, s2, s3, s4, s5 s6, s7
  @#endif
  @#if slong==8
  s1, s2, s3, s4, s5 s6, s7, s8
  @#endif
  @#if slong==9
  s1, s2, s3, s4, s5 s6, s7, s8,s9
  @#endif
  @#if slong==10
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10
  @#endif
  @#if slong==12
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12
  @#endif
  @#if slong==16
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  @#endif
  @#if slong==20
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20
  @#endif
  @#if slong==28
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28
  @#endif
  @#if slong==40
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40
  @#endif
  @#if slong==50
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40,s41, s42, s43, s44, s45 s46, s47, s48,s49, s50
  @#endif
  @#if slong==60
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40,s41, s42, s43, s44, s45 s46, s47, s48,s49, s50
  s51, s52, s53, s54, s55 s56, s57, s58,s59, s60
  @#endif

   @#if slong==100
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40,s41, s42, s43, s44, s45 s46, s47, s48,s49, s50
  s51, s52, s53, s54, s55 s56, s57, s58,s59, s60
  s61 s62 s63 s64 s65 s66 s67 s68 s69 
  s70 s71 s72 s73 s74 s75 s76 s77 s78 s79
  s80 s81 s82 s83 s84 s85 s86 s87 s88 s89 
  s90 s91 s92 s93 s94 s95 s96 s97 s98 s99 s100 
  @#endif

// var s1, s2, s3, s4, s5
 //s6, s7, s8, s9, 
 //s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 
 //s20 s21 s22 s23 s24 s25 s26 s27 s28 s29
 //s30 s31 s32 s33 s34 s35 s36 s37 s38 s39 
 //s40 s41 s42 s43 s44 s45 s46 s47 s48 s49
 //s50  s51 s52 s53 s54 s55 s56 s57 s58 s59
 //s60 s61 s62 s63 s64 s65 s66 s67 s68 s69 
 //s70 s71 s72 s73 s74 s75 s76 s77 s78 s79  
 //s80 s81 s82 s83 s84 s85 s86 s87 s88 s89 
 //s90 s91 s92 s93 s94 s95 s96 s97 s98 s99 s100 

 @#if tfp_normal==1
 y_g, c_g, tiv_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp,tfpu,u,a, c,k,iv,h,w,r,rr,p,ppai,m,pf,pf_exp,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,pfn,in,lamdan,yg,hg,fpai,mcgap,rd,rdn,an,nf,nfn,pinf,uc,um,uh,tiv, tivn ynobs,mcgape, mc, mcn  mce, fpaie, paie, paiee,ppaie, inftr,  tfpn, tq,tqn, shu, shi, shc, shh, shue1 shue3 shue4 shue8  aa aan sp stk  ;
 @#endif

 @#if tfp_normal==0
      @#if tfplong==28
      tf1, tf2, 
     @#endif
 y_g, c_g, tiv_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp,tfpu,u,a, c,k,iv,h,w,r,rr,p,ppai,m,pf,pf_exp,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,pfn,in,lamdan,yg,hg,fpai,mcgap,rd,rdn,an,nf,nfn,pinf,uc,um,uh,tiv, tivn ynobs,mcgape, mc, mcn  mce, fpaie, paie, paiee,ppaie, inftr,  tfpn, tq,tqn, shu, shi, shc, shh, shue1 shue3 shue4 shue8  aa aan sp stk  ;
 @#endif 



@#endif
 
@#if ELB==2 
 var i, y, y_g, c_g, tiv_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,tfp,tfpu,u,a, c,k,iv,h,w,r,rr,p,ppai,m,pf,pf_exp,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,pfn,in,lamdan,yg,hg,fpai,mcgap,rd,rdn,an,nf,nfn,pinf,uc,um,uh,tiv, tivn ynobs,mcgape, mc, mcn  mce, fpaie, paie, paiee,ppaie, inftr,  tfpn, tq,tqn, shu, shi, shc, shh, shue1 shue3 shue4 shue8  aa aan sp stk;      @#endif
@#endif

 
@#if ELB==0
varexo   ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8 eue9 eue10 eue11 eue12 eue13 eue14 eue15 eue me mee meee;
@#endif
@#if ELB==1
varexo  ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8 eue9 eue10 eue11 eue12 eue13 eue14 eue15 eue me mee meee;
//varexo  ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8  eue10  eue me mee meee;
@#endif
@#if ELB==2
varexo v1 v2 v3 v4 v5 ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8 eue9 eue10 eue11 eue12 eue13 eue14 eue15 eue me mee meee;
@#endif

//@#endif 
 @#if roten==0
parameters tau,  hb,  xxx, rhoi,xpai, xy, gamma, delta, phi, theta, rho, psi, epsilon,   alfa, rhoum,rhouc, rhouh, rhou,rhoud,rhouf, sigc, sigh, sigm, ss, rho_eta, eta1, eta2, eta3, eta4,eta5,eta6,eta7,eta8,iss, rss, yss, kss, css,wss,mss, rdss, pfss,  hss, ivss, lamdass, nfss,x,ggss;
 @#endif

 @#if roten==1
parameters tau,  hb,  xxx, rhoi,xpai, xy, gamma, delta, phi, theta, rot, psi, epsilon,   alfa, rhoum,rhouc, rhouh, rhou,rhoud,rhouf, sigc, sigh, sigm, ss, rho_eta, eta1, eta2, eta3, eta4,eta5,eta6,eta7,eta8,iss, rss, yss, kss, css,wss,mss, rdss, pfss,  hss, ivss, lamdass, nfss,x,ggss;
 @#endif



@#endif




@#if tech==0
  @#if ELB==0
 var 
 @#if tfp_normal==1
 y_g, c_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp, tfpu,u,c,k,iv,h,w,r,rr,p,ppai,m,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,in,lamdan,yg,hg,mcgap,uc,um,uh, ynobs, fpai,mcgape, mc,mcn,mce, fpaie, paie, paiee,ppaie,  tfpn,tq,tqn,shu, shi, shc, shh, shue1 sp  stk ;
 @#endif 

 @#if tfp_normal==0
      @#if tfplong==28
       tf1, tf2, 
      @#endif
  y_g, c_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp, tfpu,u,c,k,iv,h,w,r,rr,p,ppai,m,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,in,lamdan,yg,hg,mcgap,uc,um,uh, ynobs, fpai,mcgape, mc,mcn,mce, fpaie, paie, paiee,ppaie,  tfpn,tq,tqn,shu, shi, shc, shh, shue1 sp  stk ;
@#endif

 @#endif

 @#if ELB==1
 
 var 
  @#if slong==0
  
  @#endif
  @#if slong==4
  s1, s2, s3, s4
  @#endif
  @#if slong==7
  s1, s2, s3, s4, s5 s6, s7
  @#endif
  @#if slong==8
  s1, s2, s3, s4, s5 s6, s7, s8
  @#endif
  @#if slong==9
  s1, s2, s3, s4, s5 s6, s7, s8 s9
  @#endif
  @#if slong==10
  s1, s2, s3, s4, s5 s6, s7, s8 s9, s10
  @#endif 
  @#if slong==12
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12
  @#endif
  @#if slong==16
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  @#endif
  @#if slong==20
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20
  @#endif
  @#if slong==28
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28
  @#endif
  
  @#if slong==40
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40
  @#endif


  @#if slong==50
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40,s41, s42, s43, s44, s45 s46, s47, s48,s49, s50
  @#endif

  @#if slong==60
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40,s41, s42, s43, s44, s45 s46, s47, s48,s49, s50
  s51, s52, s53, s54, s55 s56, s57, s58,s59, s60
  @#endif

 @#if slong==100
  s1, s2, s3, s4, s5 s6, s7, s8,s9, s10,s11, s12, s13, s14, s15 s16
  s17, s18,s19, s20,s21, s22, s23, s24, s25 s26 s27, s28, s29 s30
  s31, s32, s33, s34, s35 s36, s37, s38,s39, s40,s41, s42, s43, s44, s45 s46, s47, s48,s49, s50
  s51, s52, s53, s54, s55 s56, s57, s58,s59, s60
  s61 s62 s63 s64 s65 s66 s67 s68 s69 
 s70 s71 s72 s73 s74 s75 s76 s77 s78 s79  
 s80 s81 s82 s83 s84 s85 s86 s87 s88 s89 
 s90 s91 s92 s93 s94 s95 s96 s97 s98 s99 s100  
  @#endif
      
 //s9, s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 
 //s20 s21 s22 s23 s24 s25 s26 s27 s28 s29
 //s30 s31 s32 s33 s34 s35 s36 s37 s38 s39 
 //s40 s41 s42 s43 s44 s45 s46 s47 s48 s49
 //s50  s51 s52 s53 s54 s55 s56 s57 s58 s59
 //s60 s61 s62 s63 s64 s65 s66 s67 s68 s69 
 //s70 s71 s72 s73 s74 s75 s76 s77 s78 s79  
 //s80 s81 s82 s83 s84 s85 s86 s87 s88 s89 
 //s90 s91 s92 s93 s94 s95 s96 s97 s98 s99 s100  




@#if tfp_normal==1
y_g, c_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp, tfpu,u,c,k,iv,h,w,r,rr,p,ppai,m,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,in,lamdan,yg,hg,mcgap,uc,um,uh, ynobs, fpai,mcgape, mc,mcn,mce, fpaie, paie, paiee,ppaie,  tfpn,tq,tqn,shu, shi, shc, shh, shue1 sp  stk ;
@#endif
@#if tfp_normal==0
      @#if tfplong==28
      tf1, tf2, 
     @#endif
y_g, c_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,y,tfp, tfpu,u,c,k,iv,h,w,r,rr,p,ppai,m,i,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,in,lamdan,yg,hg,mcgap,uc,um,uh, ynobs, fpai,mcgape, mc,mcn,mce, fpaie, paie, paiee,ppaie,  tfpn,tq,tqn,shu, shi, shc, shh, shue1 sp  stk ;
@#endif


 @#endif

 @#if ELB==2
 var i, y, s1,y_g, c_g, iv_g, h_g, w_g, tfp_g, gg, ggn, uf, pai,tfp, tfpu,u,c,k,iv,h,w,r,rr,p,ppai,m,lamda,ud,v,pain,yn,kn,ivn,hn,cn,wn,rn,pn,in,lamdan,yg,hg,mcgap,uc,um,uh, ynobs, fpai,mcgape, mc,mcn,mce, fpaie, paie, paiee,ppaie,  tfpn,tq,tqn,shu, shi, shc, shh, shue1 sp  stk ;
  @#endif

//@#endif


@#if ELB==0
varexo ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8 eue9 eue10 eue11 eue12 eue13 eue14 eue15 eue me mee meee;
@#endif
@#if ELB==1
varexo ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8 eue9 eue10 eue11 eue12 eue13 eue14 eue15 eue me mee meee;
@#endif
@#if ELB==2
varexo v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 ei eu euc euh ef eue1 eue2 eue3 eue4 eue5 eue6 eue7 eue8 eue9 eue10 eue11 eue12 eue13 eue14 eue15 eue me mee meee;
@#endif


@#if pindex==0
 @#if roten==0
 parameters tau, hb,  xxx, rhoi,xpai, xy, gamma, delta, phi, theta, rho, rhoum,rhouc,rhouh, rhou,rhoud,rhouf, sigc, sigh, sigm, ss, iss_noa, rss_noa, yss_noa, kss_noa, css_noa,wss_noa,mss_noa,  hss_noa, ivss_noa, lamdass_noa, ggss_noa ;
 @#endif
 @#if roten==1
 parameters tau, hb,  xxx, rhoi,xpai, xy, gamma, delta, phi, theta, rot, rhoum,rhouc,rhouh, rhou,rhoud,rhouf, sigc, sigh, sigm, ss, iss_noa, rss_noa, yss_noa, kss_noa, css_noa,wss_noa,mss_noa,  hss_noa, ivss_noa, lamdass_noa, ggss_noa ;
 @#endif

@#endif
@#if pindex==1
 @#if roten==0 
 parameters index, tau, hb,  xxx, rhoi,xpai, xy, gamma, delta, phi, theta, rho, rhoum,rhouc,rhouh, rhou,rhoud,rhouf, sigc, sigh, sigm, ss, iss_noa, rss_noa, yss_noa, kss_noa, css_noa,wss_noa,mss_noa,  hss_noa, ivss_noa, lamdass_noa, ggss_noa ;
 @#endif
@#endif

//parameters tau, hb,  xxx, rhoi,xpai, xy, gamma, delta, phi, theta, rho, rhoum,rhouc,rhouh, rhou,rhoud,rhouf, sigc, sigh, sigm, ss, iss_noa, rss_noa, yss_noa, kss_noa, css_noa,wss_noa,mss_noa,  hss_noa, ivss_noa, lamdass_noa, ggss_noa ;

@#endif


rho_rot_=rho_rot;

@#if tech==1

//** data_techzero==1 section **//
//rho_rot_=rho_rot;

@#if data_techzero==1

 rho_eta=aa0(j,17);
 xxx = aa0(j,18);
 xpai = aa0(j,19); //*1.5 (CLE&Gali) *//
 xy =aa0(j,20); //* 0.5/4 (gali) 0.1 (CLE) *//

//** with  capital, habit &  Inv Adj cost **//
  @#if simple==0
  hb=aa0(j,21); % Internal habit formation param.
  ss=aa0(j,24);
  theta = 1/3;
  @#endif
//** no capital, no habit & no Inv Adj cost **//
  @#if simple==1
  hb=0.0000001*aa0(j,21); % Internal habit formation param.
  ss=0.0000001*aa0(j,24);
  theta =1/3; % to small value does not satisfys BK condition with tec==1
  //theta = 0.0000001; % to small value does not satisfys BK condition with tec==1
  @#endif
//** with capital and no habit & no Inv Adj cost **//
  @#if simple==2
  hb=0.0000001*aa0(j,21); % Internal habit formation param.
  ss=0.0000001*aa0(j,24);
  //ss=aa0(j,29);
  theta =1/3;
  @#endif

//** with capital & Inv Adj, But No habit **//
  @#if simple==3
  hb=0.0000001*aa0(j,21); % Internal habit formation param.
  ss=aa0(j,24);
  theta =1/3;
  @#endif

//** with capital & habit, But NO Inv Adj cost **//
  @#if simple==4
  hb=aa0(j,21); % Internal habit formation param.
  ss=0.0000001*aa0(j,24);
  theta =1/3;
  @#endif



 //rho =aa0(j,22);  //** 0.75 free param& rho=0 is flexible price
 //sigh =aa0(j,28); 
 sigc =aa0(j,23); 
 sigm = 2.56; //* CEL=9
 phi = aa0(j,25);
 //phi = 4.84;
 psi = aa0(j,26);
 
@#if lwrhou==0
 rhou = aa0(j,27); //*0.9515 (mediun value) *//
@#endif
@#if lwrhou==1
rhou = rhou_new;
@#endif


 rhoi = aa0(j,28);//*0.5 (Gali) &0.15(Smet) *//
 rhoud = 0.0;
 rhouh = aa0(j,29); //**this needs to be high to get good results
 rhouc = aa0(j,30); //**this needs to be high to get good results
 rhouf = aa0(j,31); //**this needs to be high to get good results

 @#if ashock==1
 alfa =aa0(j,32);
 @#endif
 @#if ashock==0
 alfa =alfa_n;
 @#endif


rhoum =0.0;
//sigc=1.00;
gamma =0.99; % discount factor  
delta = 0.10000000/4;  %capital depreciation rate
//theta = 0.33;
//theta = 0.01;
notec=0;
epsilon = 0.1/4;
tau =0.18;
//phi=6.0;
sigh=2.0;


@#if roten==0
 rho =aa0(j,22);  //** 0.75 free param& rho=0 is flexible price
@#endif
@#if roten==1
 rot =((rho_rot_)*psi*(phi-1))/(  1-rho_rot_*psi-rho_rot_*(psi)*gamma + ((rho_rot_*psi)^2)*gamma ) ;
 //rot =((rho_rot_)*psi*(phi-1))/(  1-rho_rot_*psi-rho_rot_*(psi^2)*gamma + ((rho_rot_*psi)^2)*gamma ) ;
@#endif



eta1=( (1+rho_eta+(rho_eta^2)+(rho_eta^3)+(rho_eta^4)+(rho_eta^5)+(rho_eta^6)+(rho_eta^7))^(-1) );
eta2=eta1*(rho_eta);
eta3=eta1*(rho_eta)^2; 
eta4=eta1*(rho_eta)^3;
eta5=eta1*(rho_eta)^4;
eta6=eta1*(rho_eta)^5;
eta7=eta1*(rho_eta)^6;
eta8=eta1*(rho_eta)^7;


iss = (1/gamma)-1;
rss = iss + delta;
wss = (((phi-1)/phi)*(1-theta)*(((1-theta)/theta)^(-theta))*(rss^(-theta)))^(1/(1-theta));
yss_hss = ((theta/(1-theta))*(wss/rss))^theta;
kss_hss = (yss_hss)^(1/theta);
nfss= (1-psi)/epsilon;



g1_t8 = (1/(1-psi*gamma))*(1-psi)*( ( eta1*(1+iss) + eta2*((1+iss)^2) + eta3*((1+iss)^3) +eta4*((1+iss)^4) +eta5*((1+iss)^5) +eta6*((1+iss)^6)  +eta7*((1+iss)^7)  +eta8*((1+iss)^8)  )^(-1) )*(  1-  (1/(1-theta))*( ( (1-theta)/theta )^theta )*( rss^theta)*( wss^(1-theta) )  );  
//g2_t8 = (1-g1_t8)*(yss_hss) - (delta*kss_hss);
g2_t8 = (1-g1_t8)*(yss_hss) - (delta*kss_hss)- tau*(yss_hss);
g1 = g1_t8; 
g2 = g2_t8;
css_hss = g2_t8; 
etas = ( eta1*(1+iss) + eta2*((1+iss)^2) + eta3*((1+iss)^3) +eta4*((1+iss)^4) +eta5*((1+iss)^5) +eta6*((1+iss)^6) +eta7*((1+iss)^7) +eta8*((1+iss)^8) );

hss= (wss*(css_hss^(-sigc))*((1-hb)^(-sigc))*(1-hb*gamma))^(1/(sigh+sigc)); 
css=(css_hss)*hss;
yss = (((theta/(1-theta))*(wss/rss))^theta)*hss;
kss = (yss_hss^(1/theta))*hss;

rdss = g1*yss;
x=((nfss)^(1+alfa))/rdss; % x is (kappa_bar*delta) in the paper

pfss = (1/(1-psi))*etas*rdss; % pfss is the steady state value of th epresent value of monopoly profits stream 
lamdass = (1-hb*gamma)*((1-hb)*css)^(-sigc); % lamdass = the steady state velu of CHI in the paper
mss = (((1-hb)*css)^(sigc/sigm))*(((1+iss)/iss)^(1/sigm))*((1-hb*gamma)^(-1/sigm));
ivss = delta*kss;
ggss =tau*yss; % ggss=staedy state value of gg, govt expnditure

@#endif
//** End of data_techzero==1 section **//


@#endif




@#if tech==0

@#if data_techzero==0  

@#if pindex==0

xxx = aa0(j,17);
xpai = aa0(j,18); //*1.5 (CLE&Gali) *//
xy =aa0(j,19); //* 0.5/4 (gali) 0.1 (CLE) *//


//** No capital, no habit & no Inv Adj cost **//
  @#if simple==0
  hb=aa0(j,20); % Internal habit formation param.
  ss=aa0(j,23);
  theta = 1/3;
  @#endif
//** No capital, no habit & no Inv Adj cost **//
  @#if simple==1
  hb=0.0000001*aa0(j,20); % Internal habit formation param.
  ss=0.0000001*aa0(j,23);
  theta = 0.0000001;
  //theta = 1/3;
  @#endif
//** With capital and no habit & no Inv Adj cost **//
  @#if simple==2
  hb=0.0000001*aa0(j,20); % Internal habit formation param.
  ss=0.0000001*aa0(j,23);
  //ss=aa0(j,28);
  theta = 1/3;
  @#endif


//** with capital & Inv Adj, But No habit **//
  @#if simple==3
  hb=0.0000001*aa0(j,20); % Internal habit formation param.
  //hb=0.47; % Internal habit formation param.
  ss=aa0(j,23);
  theta =1/3;
  @#endif

//** with capital & habit, But NO Inv Adj cost **//
  @#if simple==4
  hb=aa0(j,20); % Internal habit formation param.
  ss=0.0000001*aa0(j,23);
  theta =1/3;
  @#endif

//rho =aa0(j,21);  //** 0.75 free param& rho=0 is flexible price
sigc =aa0(j,22); 
sigm = 2.56; //* CEL=9
phi = aa0(j,24);

@#if lwrhou==0
 rhou = aa0(j,25); //*0.9515 (mediun value) *//
@#endif
@#if lwrhou==1
rhou = rhou_new;
@#endif


rhoi = aa0(j,26);//*0.5 (Gali) &0.15(Smet) *//
rhoud = 0.5;
rhouh = aa0(j,27); //**this needs to be high to get good results
rhouc = aa0(j,28); //**this needs to be high to get good results
rhouf = aa0(j,29); //**this needs to be high to get good results

@#endif


@#if pindex==1

index=aa0(j,17); 
 xxx = aa0(j,18);
 xpai = aa0(j,19); //*1.5 (CLE&Gali) *//
 xy =aa0(j,20); //* 0.5/4 (gali) 0.1 (CLE) *//

 @#if simple==0

  hb=aa0(j,21); % Internal habit formation param.
  ss=aa0(j,24);
  theta = 1/3;
  @#endif
//** No capital, no habit & no inv Adj cost **//
  @#if simple==1
  hb=0.0000001*aa0(j,21); % Internal habit formation param.
  ss=0.0000001*aa0(j,24);
  theta = 0.000001;
  @#endif
//** With capital, and no habit & no inv Adj cost **//
  @#if simple==2
  hb=0.0000001*aa0(j,21); % Internal habit formation param.
  ss=0.0000001*aa0(j,24);
  theta = 1/3;
  @#endif
 
//** with capital & Inv Adj, But No habit **//
  @#if simple==3
  hb=0.0000001*aa0(j,21); % Internal habit formation param.
  ss=aa0(j,24);
  theta = 1/3;
  @#endif

@#if simple==4
   hb=0.5*aa0(j,21); % Internal habit formation param.
  ss=0.5*aa0(j,24);
  theta = 1/3;
 @#endif

//rho =aa0(j,22);  //** 0.75 free param& rho=0 is flexible price
//sigh =aa0(j,22); 
sigc =aa0(j,23); 
sigm = 2.56; //* CEL=9
phi = aa0(j,25);


@#if lwrhou==0
 rhou = aa0(j,26); //*0.9515 (mediun value) *//
 @#endif 
 @#if lwrhou==1
 rhou =rhou_new;
 @#endif

rhoi = aa0(j,27);//*0.5 (Gali) &0.15(Smet) *//
rhoud = 0.5;
//rhouh = 0.9;
rhouh = aa0(j,28); //**this needs to be high to get good results
rhouc = aa0(j,29); //**this needs to be high to get good results
rhouf = aa0(j,30); //**this needs to be high to get good results

@#endif 


rhoum =0.9;
//sigc=1;
gamma =0.99; % discount factor  
delta = 0.10000000/4;  %capital depreciation rate
//theta = 1/3;
//theta = 0.01;

notec=0;
tau=0.18;
//phi=6.0;
sigh=2.0;


@#if pindex==0
 @#if roten==0
 rho =aa0(j,21);  //** 0.75 free param& rho=0 is flexible price
 @#endif
 @#if roten==1
 rot =((rho_rot_)*(phi-1))/(  1-rho_rot_-rho_rot_*gamma + ((rho_rot_)^2)*gamma ) ;
 //rot =((rho_rot_)*psi*(phi-1))/(  1-rho_rot_*psi-rho_rot_*(psi^2)*gamma + ((rho_rot_*psi)^2)*gamma ) ;
 @#endif
@#endif

@#if pindex==1
 @#if roten==0
 rho =aa0(j,22);  //** 0.75 free param& rho=0 is flexible price
 @#endif
@#endif



iss_noa = (1/gamma)-1;
rss_noa = iss_noa + delta;
wss_noa = (((phi-1)/phi)*(1-theta)*(((1-theta)/theta)^(-theta))*(rss_noa^(-theta)))^(1/(1-theta));
yss_hss_noa = ((theta/(1-theta))*(wss_noa/rss_noa))^theta;
kss_hss_noa = (yss_hss_noa)^(1/theta);
css_hss_noa = yss_hss_noa - delta*kss_hss_noa- tau*yss_hss_noa; //* including the gov expenditure part "-tau*yss_hss_noa"
hss_noa = (wss_noa*(css_hss_noa^(-sigc))*((1-hb)^(-sigc))*(1-hb*gamma))^(1/(sigh+sigc));
yss_noa = (((theta/(1-theta))*(wss_noa/rss_noa))^theta)*hss_noa;
kss_noa = (yss_hss_noa^(1/theta))*hss_noa;
css_noa = css_hss_noa*hss_noa;
mss_noa = (((1-hb)*css_noa)^(sigc/sigm))*(((1+iss_noa)/iss_noa)^(1/sigm))*((1-hb*gamma)^(-1/sigm));
ivss_noa = delta*kss_noa;
ggss_noa =tau*yss_noa; % ggss=staedy state value of gg, govt expnditure

lamdass_noa = (1-hb*gamma)*((1-hb)*css_noa)^(-sigc);
@#endif

@#endif




model(linear);

@#if tech==1


 rd=(1+alfa)*(eta1*nf(-7)+eta2*nf(-6)+eta3*nf(-5)+eta4*nf(-4)+eta5*nf(-3)+eta6*nf(-2)+eta7*nf(-1)+eta8*nf);
 pf(+8)=alfa*nf+((nfss^alfa)/(epsilon*x*pfss))* (  iss*(eta1+(1+iss)*eta2+((1+iss)^2)*eta3+((1+iss)^3)*eta4+((1+iss)^4)*eta5+((1+iss)^5)*eta6 +((1+iss)^6)*eta7 +((1+iss)^7)*eta8)*(1/iss)*i(+7) +  iss*(1+iss)*(eta2+((1+iss)^1)*eta3+((1+iss)^2)*eta4+((1+iss)^3)*eta5+((1+iss)^4)*eta6 +((1+iss)^5)*eta7 +((1+iss)^6)*eta8)*(1/iss)*i(+6) + iss*((1+iss)^2)*(eta3+((1+iss)^1)*eta4+((1+iss)^2)*eta5 +((1+iss)^3)*eta6 +((1+iss)^4)*eta7 +((1+iss)^5)*eta8)*(1/iss)*i(+5) + iss*((1+iss)^3)*(eta4+((1+iss)^1)*eta5 +((1+iss)^2)*eta6 +((1+iss)^3)*eta7 +((1+iss)^4)*eta8)*(1/iss)*i(+4) + iss*((1+iss)^4)*(eta5 +((1+iss)^1)*eta6 +((1+iss)^2)*eta7 +((1+iss)^3)*eta8)*(1/iss)*i(+3) + iss*((1+iss)^5)*(eta6 +((1+iss)^1)*eta7 +((1+iss)^2)*eta8)*(1/iss)*i(+2) + iss*((1+iss)^6)*(eta7 +((1+iss)^1)*eta8)*(1/iss)*i(+1) + iss*((1+iss)^7)*(eta8)*(1/iss)*i + eta1*(1+iss)*(p(+7)-p(+8)) + eta2*((1+iss)^2)*(p(+6)-p(+8)) + eta3*((1+iss)^3)*(p(+5)-p(+8)) + eta4*((1+iss)^4)*(p(+4)-p(+8)) + eta5*((1+iss)^5)*(p(+3) -p(+8)) + eta6*((1+iss)^6)*(p(+2) -p(+8)) + eta7*((1+iss)^7)*(p(+1) -p(+8)) + eta8*((1+iss)^8)*(p -p(+8))  );    
 a = (1-psi)*nf(-7) + psi*a(-1);
 
c-hb*c(-1)= (1+gamma*hb)*(c(+1)-hb*c) - gamma*hb*(c(+2)-hb*c(+1)) - ((1-hb)/sigc)*(1-gamma*hb)*((iss/(1+iss))*(1/iss)*i + p - p(+1) + uc(+1) + ud(+1)) + ((1-hb)/sigc)*(uc + ud + gamma*hb*(uc(+2) +ud(+2))) ; 
sigh*h = w - uh + (1/(1-hb*gamma))*( (-sigc/(1-hb))*(c - hb*c(-1)) + uc ) + (hb*gamma/(1-hb*gamma))*( (sigc/(1-hb))*(c(+1)-hb*c) - uc(+1) - ud(+1) +ud );
sigm*(m-p) = (-1/(1+iss))*(1/iss)*i + um + (1/(1-hb*gamma))*( (sigc/(1-hb))*(c-hb*c(-1)) -uc + (hb*gamma)*( (-sigc/(1-hb))*(c(+1)-hb*c) + uc(+1) +ud(+1) - ud) );
lamda = (1-delta)*gamma*lamda(+1) - ((1-(1-delta)*gamma)/(1-hb*gamma))*( (sigc/(1-hb))*(c(+1)-hb*c) - (1/rss)*r(+1) - uc(+1) - ud(+1) - hb*gamma*( (sigc/(1-hb))*(c(+2)-hb*c(+1)) - (1/rss)*r(+1) -uc(+2) -ud(+2) ) );
iv =  (gamma/(1+gamma))*iv(+1) + (1/(1+gamma))*iv(-1) + (1/(ss*(1+gamma)))*lamda  + (1/(ss*(1+gamma)*(1-hb*gamma)))*( (sigc/(1-hb))*(c-hb*c(-1)) - uc - ud +gamma*hb*( (-sigc/(1-hb))*(c(+1)-hb*c) + uc(+1) +ud(+1) ) ) ;
//yss*y = css*c + ivss*iv + rdss*rd;
yss*y = css*c + ivss*iv + rdss*rd +ggss*gg;

(1-delta)*k(-1) +delta*iv - k = 0;
tiv= (ivss*iv + rdss*rd)/(ivss+rdss); //*total investment: R&D investment+ capital investment
y = (1/(phi-1))*a(-1) + u + theta*k(-1) + (1-theta)*h;
h - k(-1) - (1/rss)*r + w = 0;

@#if roten==0
pai = gamma*(pai(+1)) + (((1-gamma*rho*psi)*(1-rho*psi))/(rho*psi))*(-u + theta*(1/rss)*r +(1-theta)*w - (1/(phi-1))*a(-1)) + (gamma/(phi-1))*(a - a(-1)) - (1/(phi-1))*(a(-1) - a(-2));
@#endif
@#if roten==1
pai = gamma*psi*(pai(+1)) + ((phi-1)/rot)*(-u + theta*(1/rss)*r +(1-theta)*w ) + (gamma*psi/(phi-1))*(a) -(((phi-1)+rot+gamma*psi*rot)/((phi-1)*rot))* a(-1) + (1/(phi-1))*a(-2);
@#endif

@#if roten==0
pfss*pf - (gamma*psi)*pfss*pf(+1) + (gamma*psi)*pfss*(p - p(+1) + iss*(1/iss)*i) = (1/phi)*yss*y +((phi-1)/phi)*yss*u - ((phi-1)/phi)*(1-theta)*yss*w -  ((phi-1)/phi)*theta*yss*(1/rss)*r;
@#endif
@#if roten==1
pfss*pf - (gamma*psi)*pfss*pf(+1) = (1/phi)*yss*y +((phi-1)/phi)*yss*u - ((phi-1)/phi)*(1-theta)*yss*w -  ((phi-1)/phi)*theta*yss*(1/rss)*r;
@#endif

//pai = gamma*(pai(+1)) + (((1-gamma*rho*psi)*(1-rho*psi))/(rho*psi))*(-u + theta*(1/rss)*r +(1-theta)*w - (1/(phi-1))*a(-1)) + (gamma/(phi-1))*(a - a(-1)) - (1/(phi-1))*(a(-1) - a(-2));
//pfss*pf - (gamma*psi)*pfss*pf(+1) + (gamma*psi)*pfss*(p - p(+1) + iss*(1/iss)*i) = (1/phi)*yss*y +((phi-1)/phi)*yss*u - ((phi-1)/phi)*(1-theta)*yss*w -  ((phi-1)/phi)*theta*yss*(1/rss)*r;


pai = p - p(-1);
gg=(1/tau)*uf +y; // * govt expenditure

y_g=y-y(-1);
c_g=c-c(-1);
tiv_g=tiv-tiv(-1);
iv_g=iv-iv(-1);
h_g=h-h(-1);
w_g=w-w(-1);
tfp_g=tfp-tfp(-1);

rr=i-pai(+1); //*real interest rate

pf_exp=pf(+8);

///////////////////////////////////////////////////////////////
// Monetary Policy (Inerest rate rule) & interest rate shock //
//////////////////////////////////////////////////////////////
///////
//ELB//
///////
@#if ELB==1

@#if slong==0
iss*(1/iss)*i = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(-1) + (1-xxx)*((xpai)*(pai)+(xy)*(yg))+ v );
@#endif 

@#if slong==4
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1);
s4 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+3) + (1-xxx)*((xpai)*(pai(+4))+(xy)*(yg(+4)))+ v );
@#endif

@#if slong==7
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);
s7 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+6) + (1-xxx)*((xpai)*(pai(+7))+(xy)*(yg(+7)))+ v );
@#endif

@#if slong==8
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1);
s8 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+7) + (1-xxx)*((xpai)*(pai(+8))+(xy)*(yg(+8)))+ v );
@#endif

@#if slong==9
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);
s9 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+8) + (1-xxx)*((xpai)*(pai(+9))+(xy)*(yg(+9)))+ v );
@#endif

@#if slong==10
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);
s10 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+9) + (1-xxx)*((xpai)*(pai(+10))+(xy)*(yg(+10)))+ v );
@#endif

@#if slong==12
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);
s12 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+11) + (1-xxx)*((xpai)*(pai(+12))+(xy)*(yg(+12)))+ v );
@#endif

@#if slong==16
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+15) + (1-xxx)*((xpai)*(pai(+16))+(xy)*(yg(+16)))+ v );
@#endif

@#if slong==20
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);
s20 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+19) + (1-xxx)*((xpai)*(pai(+20))+(xy)*(yg(+20)))+ v );
@#endif

@#if slong==28
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+27) + (1-xxx)*((xpai)*(pai(+28))+(xy)*(yg(+28)))+ v );
@#endif

@#if slong==40
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+39) + (1-xxx)*((xpai)*(pai(+40))+(xy)*(yg(+40)))+ v );
@#endif


@#if slong==50
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
s50 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+49) + (1-xxx)*((xpai)*(pai(+50))+(xy)*(yg(+50)))+ v );
@#endif

@#if slong==60
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
s50 = s51(-1);s51 = s52(-1);s52 = s53(-1);s53 = s54(-1);s54 = s55(-1);s55 = s56(-1);s56 = s57(-1);s57 = s58(-1);s58 = s59(-1);s59 = s60(-1);
s60 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+59) + (1-xxx)*((xpai)*(pai(+60))+(xy)*(yg(+60)))+ v );
@#endif 

@#if slong==100
iss*(1/iss)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
s50 = s51(-1);s51 = s52(-1);s52 = s53(-1);s53 = s54(-1);s54 = s55(-1);s55 = s56(-1);s56 = s57(-1);s57 = s58(-1);s58 = s59(-1);s59 = s60(-1);
s60 = s61(-1);s61 = s62(-1);s62 = s63(-1);s63 = s64(-1);s64 = s65(-1);s65 = s66(-1);s66 = s67(-1);s67 = s68(-1);s68 = s69(-1);s69 = s70(-1);
s70 = s71(-1);s71 = s72(-1);s72 = s73(-1);s73 = s74(-1);s74 = s75(-1);s75 = s76(-1);s76 = s77(-1);s77 = s78(-1);s78 = s79(-1);s79 = s80(-1);
s80 = s81(-1);s81 = s82(-1);s82 = s83(-1);s83 = s84(-1);s84 = s85(-1);s85 = s86(-1);s86 = s87(-1);s87 = s88(-1);s88 = s89(-1);s89 = s90(-1);
s90 = s91(-1);s91 = s92(-1);s92 = s93(-1);s93 = s94(-1);s94 = s95(-1);s95 = s96(-1);s96 = s97(-1);s97 = s98(-1);s98 = s99(-1);s99 = s100(-1);

s100 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+99) + (1-xxx)*((xpai)*(pai(+100))+(xy)*(yg(+100)))+ v );
@#endif 
 
//s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);s16 = s17(-1);s17 = s18(-1);s18 = s19(-1);s19 = s20(-1);
//s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);s28 = s29(-1);s29 = s30(-1);
//s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
//s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
//s50 = s51(-1);s51 = s52(-1);s52 = s53(-1);s53 = s54(-1);s54 = s55(-1);s55 = s56(-1);s56 = s57(-1);s57 = s58(-1);s58 = s59(-1);s59 = s60(-1);
//s60 = s61(-1);s61 = s62(-1);s62 = s63(-1);s63 = s64(-1);s64 = s65(-1);s65 = s66(-1);s66 = s67(-1);s67 = s68(-1);s68 = s69(-1);s69 = s70(-1);
//s70 = s71(-1);s71 = s72(-1);s72 = s73(-1);s73 = s74(-1);s74 = s75(-1);s75 = s76(-1);s76 = s77(-1);s77 = s78(-1);s78 = s79(-1);s79 = s80(-1);
//s80 = s81(-1);s81 = s82(-1);s82 = s83(-1);s83 = s84(-1);s84 = s85(-1);s85 = s86(-1);s86 = s87(-1);s87 = s88(-1);s88 = s89(-1);s89 = s90(-1);
//s90 = s91(-1);s91 = s92(-1);s92 = s93(-1);s93 = s94(-1);s94 = s95(-1);s95 = s96(-1);s96 = s97(-1);s97 = s98(-1);s98 = s99(-1);s99 = s100(-1);

//s100 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+99) + (1-xxx)*((xpai)*(pai(+100))+(xy)*(yg(+100))) );
//s90 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+89) + (1-xxx)*((xpai)*(pai(+90))+(xy)*(yg(+90))) );

//s80 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+79) + (1-xxx)*((xpai)*(pai(+80))+(xy)*(yg(+80))) );
//s80 = ((1+iss)^(xxx))*((1-xxx)*((xpai)*(pai(+80))+(xy)*(yg(+80))) );

//s20 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+19) + (1-xxx)*((xpai)*(pai(+20))+(xy)*(yg(+20))) );

//s20 = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(+19) + (1-xxx)*((xpai)*(pai(+20))+(xy)*(yg(+20)))+ v(+21) );

@#endif

@#if ELB==2

iss*(1/iss)*i = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(-1) + (1-xxx)*((xpai)*(pai)+(xy)*(yg)) + v)+v1(-1)+v2(-2)+v3(-3)+v4(-4)+v5(-5);

@#endif

@#if ELB==0
iss*(1/iss)*i = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(-1) + (1-xxx)*((xpai)*(pai)+(xy)*(yg)) + v);

//iss*(1/iss)*i = ((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(-1) + (1-xxx)*((xpai)*(pai(-2))+(xy)*(yg(-2))) + v);

//iss*(1/iss)*i = ((1+iss)^(xxx))*((1-xxx)*((xpai)*(pai(-5))) + v);

//(iss/(1+iss))*(1/iss)*i + p - p(+1)=2*(xpai)*(pai(-1))+v;

//iss*(1/iss)*i = ( (1-xxx)*((xpai)*(pai(-8))+(xy)*(yg(-8))) + v);

//(iss/(1+iss))*(1/iss)*i + p - p(+1)=((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(-1) + (1-xxx)*((xpai)*(pai(-2))+(xy)*(yg(-2))) + v);
//(iss/(1+iss))*(1/iss)*i + p - p(+1)=( (1-xxx)*((xpai)*(pai(-7))+(xy)*(yg(-7))) + v);
//(iss/(1+iss))*(1/iss)*i + 1.2*(p - p(+1))=v;
//i + 1.2*(p - p(+1))=v;

//(iss/(1+iss))*(1/iss)*i =((1+iss)^(xxx))*(xxx*(iss/(1+iss))*(1/iss)*i(-1) + (1-xxx)*((xpai)*(pai(-1))+(xy)*(yg(-1))) + v)+r;
@#endif

@#if ishock==1
 @#if ELB==0
 v = rhoi*v(-1)+ei;
 @#endif
 @#if ELB==1
 v = rhoi*v(-1)+ei;
 @#endif
 @#if ELB==2
 v =ei;
 @#endif 

// v = rhoi*v(-1) +eue8(-8);
@#endif

@#if ishock==0
 @#if ELB==0
 v = rhoi*v(-1);
 @#endif
  @#if ELB==1
 v = rhoi*v(-1);
 @#endif
 @#if ELB==2
 v =0;
 @#endif 
@#endif

@#if fshock==1
uf = rhouf*uf(-1)-ef;
@#endif

@#if fshock==0
uf = rhouf*uf(-1);
@#endif

@#if ushock==1
 @#if tfp_normal==1
  u = rhou*u(-1) -eu + eue1(-1) + eue2(-2) + eue3(-3) +eue4(-4)+eue5(-5)+eue6(-6)+eue7(-7)+eue8(-8)+eue9(-9) +eue10(-10)+eue11(-11)+eue12(-12)+eue13(-13)+eue14(-14)+eue15(-15)+eue(-16);
  @#endif
  @#if tfp_normal==0
   

 u = -tf1 + eue1(-1) + eue2(-2) + eue3(-3) +eue4(-4)+eue5(-5)+eue6(-6)+eue7(-7)+eue8(-8)+eue9(-9) +eue10(-10)+eue11(-11)+eue12(-12)+eue13(-13)+eue14(-14)+eue15(-15)+eue(-16);
 tf1=tf2+tf2(-1)+tf2(-2)+tf2(-3)+tf2(-4)+tf2(-5)+tf2(-6)+tf2(-7)+tf2(-8)+tf2(-9)+tf2(-10)+tf2(-11)+tf2(-12)+tf2(-13)+tf2(-14)+tf2(-15)+tf2(-16)+tf2(-17)+tf2(-18)+tf2(-19)+tf2(-20)+tf2(-21)
 +tf2(-22)+tf2(-23)+tf2(-24)+tf2(-25)+tf2(-26)+tf2(-27);
 tf2=eu; 

//tf1 = tf2(-1); tf2 = tf3(-1);tf3 = tf4(-1); tf4 = tf5(-1);tf5 = tf6(-1);tf6 = tf7(-1);tf7 = tf8(-1); tf8 = tf9(-1);tf9 = tf10(-1);tf10 = tf11(-1);tf11 = tf12(-1);tf12 = tf13(-1);tf13 = tf14(-1);tf14 = tf15(-1);tf15 = tf16(-1);
 //tf16 = tf17(-1);tf17 = tf18(-1); tf18 = tf19(-1);tf19 = tf20(-1);tf20 = tf21(-1);tf21 = tf22(-1);tf22 = tf23(-1);tf23 = tf24(-1);tf24 = tf25(-1);tf25 = tf26(-1);tf26 = tf27(-1);tf27 = tf28(-1);
 //tf28= -eu;
 //tf28= -eu-etfp;
  
  @#endif
@#endif  

@#if ushock==0
 @#if news==1
     u = rhou*u(-1) + eue1(-1) + eue2(-2) + eue3(-3) +eue4(-4)+eue5(-5)+eue6(-6)+eue7(-7)+eue8(-8)+eue9(-9) +eue10(-10)+eue11(-11)+eue12(-12)+eue13(-13)+eue14(-14)+eue15(-15)+eue(-16); 
 @#endif
 @#if news==0
  u = rhou*u(-1); 
 @#endif  
@#endif

////////////////////////
// Preference shocks //
//////////////////////
@#if cshock==0
uc = rhouc*uc(-1);
@#endif
@#if cshock==1
uc = rhouc*uc(-1) +euc; 
@#endif

@#if hshock==0
uh = rhouh*uh(-1); //* Preference shock
@#endif
@#if hshock==1
uh = rhouh*uh(-1) +euh; //* Preference shock
@#endif

@#if dshock==0
ud = rhoud*ud(-1);
@#endif
@#if dshock==1
ud = rhoud*ud(-1)+eud;
@#endif

um = rhoum*um(-1);

yg=y-ynobs; //* gdp gap with measurement errors
hg = h-hn;

//pinf= (gamma/(phi-1))*(a - a(-1)) - (1/(phi-1))*(a(-1) - a(-2));
@#if roten==0
pinf= (gamma/(phi-1))*(a - a(-1)) - (1/(phi-1))*(a(-1) - a(-2))+(((1-gamma*rho*psi)*(1-rho*psi))/(rho*psi))*(-(1/(phi-1))*a(-1)) ;
@#endif
@#if roten==1
pinf=(gamma*psi/(phi-1))*(a) -(((phi-1)+rot+gamma*psi*rot)/((phi-1)*rot))* a(-1) + (1/(phi-1))*a(-1);
@#endif




mcgap=(-u + theta*(1/rss)*r +(1-theta)*w - (1/(phi-1))*an(-1)); //* (mc - mcn)
mcgape=mcgap+mee; 
mc=-u + theta*(1/rss)*r +(1-theta)*w; //*real marginal cost under sticky price
//mc=-(1/(phi-1))*a(-1)-u + theta*(1/rss)*r +(1-theta)*w; //*this real marginal cost  under sticky price
mce=mc+mee;
fpai = pai(+1);
ppai = pai(-1);
fpaie = pai(+1)+meee;
paiee=pai+meee+me;//*pai with 2sls errors & measument errors
paie=pai+me;//*pai with measument errors
ppaie=paie(-1);//*ppai with measument errors


//inftr =  (((1-gamma*rho*psi)*(1-rho*psi))/(rho*psi))*(- (1/(phi-1))*a(-1)) + (gamma/(phi-1))*(a - a(-1)) - (1/(phi-1))*(a(-1) - a(-2)); //*the residural part of inflation eqn
@#if roten==0
inftr =  (((1-gamma*rho*psi)*(1-rho*psi))/(rho*psi))*(- (1/(phi-1))*a(-1)) + (gamma/(phi-1))*(a - a(-1)) - (1/(phi-1))*(a(-1) - a(-2)); //*the residural part of inflation eqn
@#endif
@#if roten==1
inftr =  (gamma*psi/(phi-1))*(a) -(((phi-1)+rot+gamma*psi*rot)/((phi-1)*rot))* a(-1) + (1/(phi-1))*a(-1); //*the residural part of inflation eqn
@#endif




tfp=(1)*((1/(phi-1))*a(-1) + u) ;
//tfp= u ;

tfpu=u;
shu=eu;
shi=ei;
shc=euc;
shh=euh;
shue1=eue1;
shue3=eue3;
shue4=eue4;
shue8=eue8;
aa=a(-1);

tq=lamda-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-c+hb*c(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-c(+1)+hb*c) + uc(+1)+ud(+1) ) );
sp=tq+k(-1); 
stk=pf+sp;
//*stk is the sum of market value of capital and the intermediate firm *//  
//* q = stock price/capita *//  


//////////////////////////
//* natural variables *//
////////////////////////
 
 rdn=(1+alfa)*(eta1*nfn(-7)+eta2*nfn(-6)+eta3*nfn(-5)+eta4*nfn(-4)+eta5*nfn(-3)+eta6*nfn(-2)+eta7*nfn(-1)+eta8*nfn);
 pfn(+8)=alfa*nfn+((nfss^alfa)/(epsilon*x*pfss))* (  iss*(eta1+(1+iss)*eta2+((1+iss)^2)*eta3+((1+iss)^3)*eta4+((1+iss)^4)*eta5+((1+iss)^5)*eta6 +((1+iss)^6)*eta7 +((1+iss)^7)*eta8)*(1/iss)*in(+7) +  iss*(1+iss)*(eta2+((1+iss)^1)*eta3+((1+iss)^2)*eta4+((1+iss)^3)*eta5+((1+iss)^4)*eta6 +((1+iss)^5)*eta7 +((1+iss)^6)*eta8)*(1/iss)*in(+6) + iss*((1+iss)^2)*(eta3+((1+iss)^1)*eta4+((1+iss)^2)*eta5 +((1+iss)^3)*eta6 +((1+iss)^4)*eta7 +((1+iss)^5)*eta8)*(1/iss)*in(+5) + iss*((1+iss)^3)*(eta4+((1+iss)^1)*eta5 +((1+iss)^2)*eta6 +((1+iss)^3)*eta7 +((1+iss)^4)*eta8)*(1/iss)*in(+4) + iss*((1+iss)^4)*(eta5 +((1+iss)^1)*eta6 +((1+iss)^2)*eta7 +((1+iss)^3)*eta8)*(1/iss)*in(+3) + iss*((1+iss)^5)*(eta6 +((1+iss)^1)*eta7 +((1+iss)^2)*eta8)*(1/iss)*in(+2) + iss*((1+iss)^6)*(eta7 +((1+iss)^1)*eta8)*(1/iss)*in(+1) + iss*((1+iss)^7)*(eta8)*(1/iss)*in + eta1*(1+iss)*(pn(+7)-pn(+8)) + eta2*((1+iss)^2)*(pn(+6)-pn(+8)) + eta3*((1+iss)^3)*(pn(+5)-pn(+8)) + eta4*((1+iss)^4)*(pn(+4)-pn(+8)) + eta5*((1+iss)^5)*(pn(+3) -pn(+8)) + eta6*((1+iss)^6)*(pn(+2) -pn(+8)) + eta7*((1+iss)^7)*(pn(+1) -pn(+8)) + eta8*((1+iss)^8)*(pn -pn(+8))  );    
 an = (1-psi)*nfn(-7) + psi*an(-1);
 
cn-hb*cn(-1)= (1+gamma*hb)*(cn(+1)-hb*cn) - gamma*hb*(cn(+2)-hb*cn(+1)) - ((1-hb)/sigc)*(1-gamma*hb)*((iss/(1+iss))*(1/iss)*in + pn - pn(+1) + uc(+1) + ud(+1)) + ((1-hb)/sigc)*(uc + ud + gamma*hb*(uc(+2) +ud(+2))) ; 
sigh*hn = wn - uh + (1/(1-hb*gamma))*( (-sigc/(1-hb))*(cn - hb*cn(-1)) + uc ) + (hb*gamma/(1-hb*gamma))*( (sigc/(1-hb))*(cn(+1)-hb*cn) - uc(+1) - ud(+1) +ud );
sigm*(0-pn) = (-1/(1+iss))*(1/iss)*in + um + (1/(1-hb*gamma))*( (sigc/(1-hb))*(cn-hb*cn(-1)) -uc + (hb*gamma)*( (-sigc/(1-hb))*(cn(+1)-hb*cn) + uc(+1) +ud(+1) - ud) );
lamdan = (1-delta)*gamma*lamdan(+1) - ((1-(1-delta)*gamma)/(1-hb*gamma))*( (sigc/(1-hb))*(cn(+1)-hb*cn) - (1/rss)*rn(+1) - uc(+1) - ud(+1) - hb*gamma*( (sigc/(1-hb))*(cn(+2)-hb*cn(+1)) - (1/rss)*rn(+1) -uc(+2) -ud(+2) ) );
ivn =  (gamma/(1+gamma))*ivn(+1) + (1/(1+gamma))*ivn(-1) + (1/(ss*(1+gamma)))*lamdan  + (1/(ss*(1+gamma)*(1-hb*gamma)))*( (sigc/(1-hb))*(cn-hb*cn(-1)) - uc - ud +gamma*hb*( (-sigc/(1-hb))*(cn(+1)-hb*cn) + uc(+1) +ud(+1) ) ) ;
//yss*yn = css*cn + ivss*ivn + rdss*rdn;
yss*yn = css*cn + ivss*ivn + rdss*rdn +ggss*ggn;

(1-delta)*kn(-1) +delta*ivn - kn = 0;
tivn= (ivss*ivn + rdss*rdn)/(ivss+rdss);
ynobs=yn;
hn - kn(-1) - (1/rss)*rn + wn = 0;
yn = (1/(phi-1))*an(-1) + u + theta*kn(-1) + (1-theta)*hn;
0 = (((1-gamma*0*psi)*(1-0*psi)))*(-u + theta*(1/rss)*rn +(1-theta)*wn - (1/(phi-1))*an(-1)) ;

//pfss*pfn - (gamma*psi)*pfss*pfn(+1) + (gamma*psi)*pfss*(pn - pn(+1) + iss*(1/iss)*in) = (1/phi)*yss*yn +((phi-1)/phi)*yss*u - ((phi-1)/phi)*(1-theta)*yss*wn -  ((phi-1)/phi)*theta*yss*(1/rss)*rn;
@#if roten==0
pfss*pfn - (gamma*psi)*pfss*pfn(+1) + (gamma*psi)*pfss*(pn - pn(+1) + iss*(1/iss)*in) = (1/phi)*yss*yn +((phi-1)/phi)*yss*u - ((phi-1)/phi)*(1-theta)*yss*wn -  ((phi-1)/phi)*theta*yss*(1/rss)*rn;
@#endif
@#if roten==1
pfss*pfn - (gamma*psi)*pfss*pfn(+1)  = (1/phi)*yss*yn +((phi-1)/phi)*yss*u - ((phi-1)/phi)*(1-theta)*yss*wn -  ((phi-1)/phi)*theta*yss*(1/rss)*rn;
@#endif


pain = pn - pn(-1);

tfpn=((1/(phi-1))*an(-1) + u);
aan=an(-1);
tqn=lamdan-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-cn+hb*cn(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-cn(+1)+hb*cn) + uc(+1)+ud(+1) ) );
//tqn=-(lamdan-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-cn+hb*cn(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-cn(+1)+hb*cn) + uc(+1)+ud(+1) ) ));

mcn=-u + theta*(1/rss)*rn +(1-theta)*wn;
ggn= (1/tau)*uf +yn;

end;

initval;
//tf1=-0.001;
ynobs=0;
tiv=0;
p = 0; 
pai = 0;
u = 0;
ud= 0;
uc= 0;
uh= 0;
um= 0;
gg=0;
uf=0;

a = 0;
i=0;
lamda =0;
iv=0;

v=0;


nf=0;
nfn=0;


y =0 ;
k = 0;
h = 0;
iv=0;
c = 0;
m = 0;
w =0 ;
r = 0;
rd = 0;
pf =0;
//q=0;
//eue=0;

yn =0 ;
kn = 0;
hn = 0;
cn = 0;
ggn=0;
//mn = 0;
wn =0 ;
rn = 0;
rdn = 0;
pfn =0;
pn = 0; 
pain = 0;
an = 0;
in=0;
ivn=0; 
lamdan=0;
//qn=0;


hg=0;
yg=0;

end;

steady_state_model;
ynobs=0;
tiv=0;
p = 0; 
pai = 0;
u = 0;
ud= 0;
uc= 0;
uh= 0;
um= 0;
uf=0;

a = 0;
i=0;
lamda =0;


v=0;


nf=0;
nfn=0;


y =0 ;
k = 0;
h = 0;
iv=0;
c = 0;
m = 0;
w =0 ;
r = 0;
rd = 0;
gg=0;
pf =0;
//q=0;
//eue=0;

yn =0 ;
kn = 0;
hn = 0;
cn = 0;
//mn = 0;
wn =0 ;
rn = 0;
rdn = 0;
ggn=0;
pfn =0;
pn = 0; 
pain = 0;
an = 0;
in=0;
ivn=0; 
lamdan=0;
//qn=0;


hg=0;
yg=0;

end;

@#endif


@#if tech==0

c-hb*c(-1)= (1+gamma*hb)*(c(+1)-hb*c) - gamma*hb*(c(+2)-hb*c(+1)) - ((1-hb)/sigc)*(1-gamma*hb)*((iss_noa/(1+iss_noa))*(1/iss_noa)*i + p - p(+1) + uc(+1) + ud(+1)) + ((1-hb)/sigc)*(uc + ud + gamma*hb*(uc(+2) +ud(+2))) ; 
sigh*h = w - uh + (1/(1-hb*gamma))*( (-sigc/(1-hb))*(c - hb*c(-1)) + uc ) + (hb*gamma/(1-hb*gamma))*( (sigc/(1-hb))*(c(+1)-hb*c) - uc(+1) - ud(+1) +ud );
sigm*(m-p) = (-1/(1+iss_noa))*(1/iss_noa)*i + um + (1/(1-hb*gamma))*( (sigc/(1-hb))*(c-hb*c(-1)) -uc + (hb*gamma)*( (-sigc/(1-hb))*(c(+1)-hb*c) + uc(+1) +ud(+1) - ud) );
lamda = (1-delta)*gamma*lamda(+1) - ((1-(1-delta)*gamma)/(1-hb*gamma))*( (sigc/(1-hb))*(c(+1)-hb*c) - (1/rss_noa)*r(+1) - uc(+1) - ud(+1) - hb*gamma*( (sigc/(1-hb))*(c(+2)-hb*c(+1)) - (1/rss_noa)*r(+1) -uc(+2) -ud(+2) ) );
iv =  (gamma/(1+gamma))*iv(+1) + (1/(1+gamma))*iv(-1) + (1/(ss*(1+gamma)))*lamda  + (1/(ss*(1+gamma)*(1-hb*gamma)))*( (sigc/(1-hb))*(c-hb*c(-1)) - uc - ud +gamma*hb*( (-sigc/(1-hb))*(c(+1)-hb*c) + uc(+1) +ud(+1) ) ) ;


yss_noa*y = css_noa*c + ivss_noa*iv +ggss_noa*gg;
(1-delta)*k(-1) +delta*iv - k = 0;

y = u + theta*k(-1) + (1-theta)*h;
h - k(-1) - (1/rss_noa)*r + w = 0;

//pai = gamma*(pai(+1)) + (((1-gamma*rho)*(1-rho))/(rho))*(-u + theta*(1/rss_noa)*r +(1-theta)*w ) ;

@#if pindex==0
 @#if roten==0
 pai = gamma*(pai(+1)) + (((1-gamma*rho)*(1-rho))/(rho))*(-u + theta*(1/rss_noa)*r +(1-theta)*w ) ;
 @#endif

 @#if roten==1
 pai = gamma*(pai(+1)) + ((phi-1)/rot)*(-u + theta*(1/rss_noa)*r +(1-theta)*w ) ;
 @#endif
@#endif

@#if pindex==1
 @#if roten==0
 pai = ( gamma/(1+gamma*rho*index) )*(pai(+1)) + ( index/(1+gamma*rho*index) )*pai(-1)+ (  ((1-gamma*rho)*(1-rho))/( (rho)*(1+gamma*rho*index) )  )*(-u + theta*(1/rss_noa)*r +(1-theta)*w ); 
 @#endif
@#endif

pai = p - p(-1);


gg=(1/tau)*uf +y; // * govt expenditure

y_g=y-y(-1);
c_g=c-c(-1);
iv_g=iv-iv(-1);
h_g=h-h(-1);
w_g=w-w(-1);
tfp_g=tfp-tfp(-1);

tq=lamda-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-c+hb*c(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-c(+1)+hb*c) + uc(+1)+ud(+1) ) );
sp=(tq+k(-1));
stk=sp;

//tq=-(lamda-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-c+hb*c(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-c(+1)+hb*c) + uc(+1)+ud(+1) ) ));

//tq = sigc*c+lamda; //*Tobin's Q
//tq = -(css_noa^(-sigc))*sigc*c-(1/lamdass_noa)*lamda; //*Tobin's Q

rr=i-pai(+1); //*real interest rate
///////////////////////////////////////////////////////////////
// Monetary Policy (Inerest rate rule) & interest rate shock //
//////////////////////////////////////////////////////////////
@#if ELB==0
iss_noa*(1/iss_noa)*i = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) + (1-xxx)*((xpai)*(pai)+(xy)*(yg)) + v);
//iss_noa*(1/iss_noa)*i = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) + (1-xxx)*((xpai)*(pai)) + v);

//i = -(p - p(+1))+ 2*(xpai)*(pai(-2))+(xy)*(yg(-2)) +v;
//(iss_noa/(1+iss_noa))*(1/iss_noa)*i + p - p(+1)=2*(xpai)*(pai(-8))+v;

//(iss_noa/(1+iss_noa))*(1/iss_noa)*i + p - p(+1)=v;

//i = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) + (1-xxx)*((xpai)*(pai(-6))+(xy)*(yg(-6))) + v)*(1/(iss_noa*(1/iss_noa)))+pai(+1);
//i = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) +(1-xxx)*((xpai)*(pai(-12))+(xy)*(yg(-12))) + v)*(1/(iss_noa*(1/iss_noa)));
@#endif

///////
//ELB//
///////
@#if ELB==1

@#if slong==0
iss_noa*(1/iss_noa)*i= ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) + (1-xxx)*((xpai)*(pai)+(xy)*(yg))+ v );
@#endif

@#if slong==4
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1);
s4 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+3) + (1-xxx)*((xpai)*(pai(+4))+(xy)*(yg(+4)))+ v );
@#endif

@#if slong==7
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);
s7 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+6) + (1-xxx)*((xpai)*(pai(+7))+(xy)*(yg(+7)))+ v );
@#endif

@#if slong==8
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1);
s8 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+7) + (1-xxx)*((xpai)*(pai(+8))+(xy)*(yg(+8)))+ v );
@#endif

@#if slong==9
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);
s9 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+8) + (1-xxx)*((xpai)*(pai(+9))+(xy)*(yg(+9)))+ v );
@#endif


@#if slong==10
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);
s10 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+9) + (1-xxx)*((xpai)*(pai(+10))+(xy)*(yg(+10)))+ v );
@#endif

@#if slong==12
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);
s12 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+11) + (1-xxx)*((xpai)*(pai(+12))+(xy)*(yg(+12)))+ v );
@#endif

@#if slong==16
iss_noa*(1/iss_noa)*i=s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+15) + (1-xxx)*((xpai)*(pai(+16))+(xy)*(yg(+16)))+ v );
@#endif

@#if slong==20
iss_noa*(1/iss_noa)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);
s20 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+19) + (1-xxx)*((xpai)*(pai(+20))+(xy)*(yg(+20)))+ v );
@#endif

  
@#if slong==28
iss_noa*(1/iss_noa)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+27) + (1-xxx)*((xpai)*(pai(+28))+(xy)*(yg(+28)))+ v );
@#endif

@#if slong==40
iss_noa*(1/iss_noa)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+39) + (1-xxx)*((xpai)*(pai(+40))+(xy)*(yg(+40)))+ v );
@#endif

@#if slong==50
iss_noa*(1/iss_noa)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
s50 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+49) + (1-xxx)*((xpai)*(pai(+50))+(xy)*(yg(+50)))+ v );
@#endif


@#if slong==60
iss_noa*(1/iss_noa)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
s50 = s51(-1);s51 = s52(-1);s52 = s53(-1);s53 = s54(-1);s54 = s55(-1);s55 = s56(-1);s56 = s57(-1);s57 = s58(-1);s58 = s59(-1);s59 = s60(-1);
s60 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+59) + (1-xxx)*((xpai)*(pai(+60))+(xy)*(yg(+60)))+ v );
@#endif

@#if slong==100
iss_noa*(1/iss_noa)*i = s1(-1);
s1 = s2(-1); s2 = s3(-1);s3 = s4(-1); s4 = s5(-1);s5 = s6(-1);s6 = s7(-1);s7 = s8(-1); s8 = s9(-1);s9 = s10(-1);s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);
s16 = s17(-1);s17 = s18(-1); s18 = s19(-1);s19 = s20(-1);s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);
s28 = s29(-1);s29 = s30(-1);s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
s50 = s51(-1);s51 = s52(-1);s52 = s53(-1);s53 = s54(-1);s54 = s55(-1);s55 = s56(-1);s56 = s57(-1);s57 = s58(-1);s58 = s59(-1);s59 = s60(-1);
s60 = s61(-1);s61 = s62(-1);s62 = s63(-1);s63 = s64(-1);s64 = s65(-1);s65 = s66(-1);s66 = s67(-1);s67 = s68(-1);s68 = s69(-1);s69 = s70(-1);
s70 = s71(-1);s71 = s72(-1);s72 = s73(-1);s73 = s74(-1);s74 = s75(-1);s75 = s76(-1);s76 = s77(-1);s77 = s78(-1);s78 = s79(-1);s79 = s80(-1);
s80 = s81(-1);s81 = s82(-1);s82 = s83(-1);s83 = s84(-1);s84 = s85(-1);s85 = s86(-1);s86 = s87(-1);s87 = s88(-1);s88 = s89(-1);s89 = s90(-1);
s90 = s91(-1);s91 = s92(-1);s92 = s93(-1);s93 = s94(-1);s94 = s95(-1);s95 = s96(-1);s96 = s97(-1);s97 = s98(-1);s98 = s99(-1);s99 = s100(-1);

s100 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+99) + (1-xxx)*((xpai)*(pai(+100))+(xy)*(yg(+100)))+ v );
@#endif

//s4 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+3) + (1-xxx)*((xpai)*(pai(+4))+(xy)*(yg(+4)))+v );
//s8 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+7) + (1-xxx)*((xpai)*(pai(+8))+(xy)*(yg(+8)))+v );
//s4=s5(-1);s5=s6(-1);s6=s7(-1);s7=s8(-1);s8=s9(-1);s9=s10(-1);
//s10 = s11(-1);s11 = s12(-1);s12 = s13(-1);s13 = s14(-1);s14 = s15(-1);s15 = s16(-1);s16 = s17(-1);s17 = s18(-1);s18 = s19(-1);s19 = s20(-1);
//s20 = s21(-1);s21 = s22(-1);s22 = s23(-1);s23 = s24(-1);s24 = s25(-1);s25 = s26(-1);s26 = s27(-1);s27 = s28(-1);s28 = s29(-1);s29 = s30(-1);
//s30 = s31(-1);s31 = s32(-1);s32 = s33(-1);s33 = s34(-1);s34 = s35(-1);s35 = s36(-1);s36 = s37(-1);s37 = s38(-1);s38 = s39(-1);s39 = s40(-1);
//s40 = s41(-1);s41 = s42(-1);s42 = s43(-1);s43 = s44(-1);s44 = s45(-1);s45 = s46(-1);s46 = s47(-1);s47 = s48(-1);s48 = s49(-1);s49 = s50(-1);
//s50 = s51(-1);s51 = s52(-1);s52 = s53(-1);s53 = s54(-1);s54 = s55(-1);s55 = s56(-1);s56 = s57(-1);s57 = s58(-1);s58 = s59(-1);s59 = s60(-1);
//s60 = s61(-1);s61 = s62(-1);s62 = s63(-1);s63 = s64(-1);s64 = s65(-1);s65 = s66(-1);s66 = s67(-1);s67 = s68(-1);s68 = s69(-1);s69 = s70(-1);
//s70 = s71(-1);s71 = s72(-1);s72 = s73(-1);s73 = s74(-1);s74 = s75(-1);s75 = s76(-1);s76 = s77(-1);s77 = s78(-1);s78 = s79(-1);s79 = s80(-1);
//s80 = s81(-1);s81 = s82(-1);s82 = s83(-1);s83 = s84(-1);s84 = s85(-1);s85 = s86(-1);s86 = s87(-1);s87 = s88(-1);s88 = s89(-1);s89 = s90(-1);
//s90 = s91(-1);s91 = s92(-1);s92 = s93(-1);s93 = s94(-1);s94 = s95(-1);s95 = s96(-1);s96 = s97(-1);s97 = s98(-1);s98 = s99(-1);s99 = s100(-1);


//s80 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+79) + (1-xxx)*((xpai)*(pai(+80))+(xy)*(yg(+80))) );
//s90 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+89) + (1-xxx)*((xpai)*(pai(+90))+(xy)*(yg(+90))) );
//s100 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+99) + (1-xxx)*((xpai)*(pai(+100))+(xy)*(yg(+100))) );
//s50= ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+49) + (1-xxx)*((xpai)*(pai(+50))+(xy)*(yg(+50))) );
//s20 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(+19) + (1-xxx)*((xpai)*(pai(+20))+(xy)*(yg(+20))) );

@#endif

@#if ELB==2
//iss_noa*(1/iss_noa)*i =((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) + (1-xxx)*((xpai)*(pai)+(xy)*(yg)) + v) 
//+v1(-1)+v2(-2)+v3(-3)+v4(-4)+v5(-5)+v6(-6)+v7(-7)+v8(-8)+v9(-9)+v10(-10) 
//+v11(-11)+v12(-12)+v13(-13)+v14(-14)+v15(-15)+v16(-16)+v17(-17)+v18(-18)+v19(-19)+v20(-20);

iss_noa*(1/iss_noa)*i=s1(-1);

s1 = ((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i + (1-xxx)*((xpai)*(pai(+1))+(xy)*(yg(+1)))+v )
+v1+v2(-1)+v3(-2)+v4(-3)+v5(-4)+v6(-5)+v7(-6)+v8(-7)+v9(-8)+v10(-9) 
+v11(-10)+v12(-11)+v13(-12)+v14(-13)+v15(-14)+v16(-15)+v17(-16)+v18(-17)+v19(-18)+v20(-19);


//iss_noa*(1/iss_noa)*i =((1+iss_noa)^(xxx))*(xxx*(iss_noa/(1+iss_noa))*(1/iss_noa)*i(-1) + (1-xxx)*((xpai)*(pai)) + v) 
//+v1(-1)+v2(-2)+v3(-3)+v4(-4)+v5(-5)+v6(-6)+v7(-7)+v8(-8)+v9(-9)+v10(-10) 
//+v11(-11)+v12(-12)+v13(-13)+v14(-14)+v15(-15)+v16(-16)+v17(-17)+v18(-18)+v19(-19)+v20(-20);

@#endif

@#if ishock==1
 @#if ELB==0
 v = rhoi*v(-1)+ei;
 @#endif
 @#if ELB==1
 v = rhoi*v(-1)+ei;
 @#endif
 @#if ELB==2
 v =ei;
 @#endif 
@#endif

@#if ishock==0
 @#if ELB==0
 v = rhoi*v(-1);
 @#endif
  @#if ELB==1
 v = rhoi*v(-1);
 @#endif
 @#if ELB==2
 v =0;
 @#endif 
@#endif

@#if fshock==1
uf = rhouf*uf(-1)-ef;
@#endif

@#if fshock==0
uf = rhouf*uf(-1);
@#endif

@#if ushock==1

 @#if tfp_normal==1
  u = rhou*u(-1) -eu+ eue1(-1) + eue2(-2) + eue3(-3) +eue4(-4)+eue5(-5)+eue6(-6)+eue7(-7)+eue8(-8)+eue9(-9) +eue10(-10)+eue11(-11)+eue12(-12)+eue13(-13)+eue14(-14)+eue15(-15)+eue(-16) ;
  @#endif
  @#if tfp_normal==0
   

 u = -tf1+ eue1(-1) + eue2(-2) + eue3(-3) +eue4(-4)+eue5(-5)+eue6(-6)+eue7(-7)+eue8(-8)+eue9(-9) +eue10(-10)+eue11(-11)+eue12(-12)+eue13(-13)+eue14(-14)+eue15(-15)+eue(-16);
 tf1=tf2+tf2(-1)+tf2(-2)+tf2(-3)+tf2(-4)+tf2(-5)+tf2(-6)+tf2(-7)+tf2(-8)+tf2(-9)+tf2(-10)+tf2(-11)+tf2(-12)+tf2(-13)+tf2(-14)+tf2(-15)+tf2(-16)+tf2(-17)+tf2(-18)+tf2(-19)+tf2(-20)+tf2(-21)
 +tf2(-22)+tf2(-23)+tf2(-24)+tf2(-25)+tf2(-26)+tf2(-27);
 tf2=eu; 
 @#endif 

 
@#endif 

@#if ushock==0
 @#if news==1
  u = rhou*u(-1) + eue1(-1) + eue2(-2) + eue3(-3) + eue4(-4)+ eue5(-5)+ eue6(-6)+ eue7(-7)+ eue8(-8)+ eue9(-9) +eue10(-10)+eue11(-11)+eue12(-12)+eue13(-13)+eue14(-14)+eue15(-15)+eue(-16); 
 @#endif
 @#if news==0
    u = rhou*u(-1); 
 @#endif 
@#endif

 
////////////////////////
// Preference shocks //
//////////////////////
@#if dshock==1
ud = rhoud*ud(-1) +eud; //* Preference shock
@#endif

@#if dshock==0
ud = rhoud*ud(-1); //* Preference shock
@#endif

@#if cshock==1
uc = rhouc*uc(-1) +euc; //* Preference shock
@#endif

@#if cshock==0
uc = rhouc*uc(-1); //* Preference shock
@#endif


@#if hshock==1
uh = rhouh*uh(-1) +euh; //* Preference shock
@#endif

@#if hshock==0
uh = rhouh*uh(-1); //* Preference shock
@#endif


//um = rhoum*um(-1) +eum; //* Preference shock
um = rhoum*um(-1) ; //* Preference shock


//yg=y-yn; //* gdp gap
yg=y-ynobs; //* gdp gap with measurement errors
hg = h-hn;


mcgap=(-u + theta*(1/rss_noa)*r +(1-theta)*w );
mcgape=mcgap+mee;
mc=mcgap;
mce=mcgape;
//gap_nw=(-u + theta*(1/rss_noa)*r +(1-theta)*w );
fpai = pai(+1);
ppai = pai(-1);
fpaie = pai(+1)+meee;
paiee=pai+meee+me;//*pai with 2sls errors & measument errors
paie=pai+me;//*pai with measument errors
ppaie=paie(-1);

tfp=u;
tfpu=u;
shu=eu;
shi=ei;
shc=euc;
shh=euh;
shue1=eue1;

/////////////////////////
//* natural variables *//
////////////////////////


cn-hb*cn(-1)= (1+gamma*hb)*(cn(+1)-hb*cn) - gamma*hb*(cn(+2)-hb*cn(+1)) - ((1-hb)/sigc)*(1-gamma*hb)*((iss_noa/(1+iss_noa))*(1/iss_noa)*in + pn - pn(+1) + uc(+1) + ud(+1)) + ((1-hb)/sigc)*(uc + ud + gamma*hb*(uc(+2) +ud(+2))) ; 
sigh*hn = wn - uh + (1/(1-hb*gamma))*( (-sigc/(1-hb))*(cn - hb*cn(-1)) + uc ) + (hb*gamma/(1-hb*gamma))*( (sigc/(1-hb))*(cn(+1)-hb*cn) - uc(+1) - ud(+1) +ud );
//sigm*(mn-pn) = (-1/(1+iss_noa))*(1/iss_noa)*in + um + (1/(1-hb*gamma))*( (sigc/(1-hb))*(cn-hb*cn(-1)) -uc + (hb*gamma)*( (-sigc/(1-hb))*(cn(+1)-hb*cn) + uc(+1) +ud(+1) - ud) );
sigm*(0-pn) = (-1/(1+iss_noa))*(1/iss_noa)*in + um + (1/(1-hb*gamma))*( (sigc/(1-hb))*(cn-hb*cn(-1)) -uc + (hb*gamma)*( (-sigc/(1-hb))*(cn(+1)-hb*cn) + uc(+1) +ud(+1) - ud) );

lamdan = (1-delta)*gamma*lamdan(+1) - ((1-(1-delta)*gamma)/(1-hb*gamma))*( (sigc/(1-hb))*(cn(+1)-hb*cn) - (1/rss_noa)*rn(+1) - uc(+1) - ud(+1) - hb*gamma*( (sigc/(1-hb))*(cn(+2)-hb*cn(+1)) - (1/rss_noa)*rn(+1) -uc(+2) -ud(+2) ) );
ivn =  (gamma/(1+gamma))*ivn(+1) + (1/(1+gamma))*ivn(-1) + (1/(ss*(1+gamma)))*lamdan  + (1/(ss*(1+gamma)*(1-hb*gamma)))*( (sigc/(1-hb))*(cn-hb*cn(-1)) - uc - ud +gamma*hb*( (-sigc/(1-hb))*(cn(+1)-hb*cn) + uc(+1) +ud(+1) ) ) ;

 yss_noa*yn = css_noa*cn + ivss_noa*ivn +ggss_noa*ggn;
(1-delta)*kn(-1) +delta*ivn - kn = 0;
//ynobs=yn+me;
ynobs=yn;

hn - kn(-1) - (1/rss_noa)*rn + wn = 0;
yn = u + theta*kn(-1) + (1-theta)*hn;
0 = (((1-gamma*0)*(1-0)))*(-u + theta*(1/rss_noa)*rn +(1-theta)*wn ) ;

pain = pn - pn(-1);
//mn = mn(-1);
//mn = 0;

//tqn = sigc*cn+lamdan; //*Tobin's Q
tfpn=u;
tqn=lamdan-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-cn+hb*cn(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-cn(+1)+hb*cn) + uc(+1)+ud(+1) ) );
//tqn=-(lamdan-(1/(1-gamma*hb))*( (sigc/(1-hb))*(-cn+hb*cn(-1))+uc+ud - gamma*hb*( (sigc/(1-hb))*(-cn(+1)+hb*cn) + uc(+1)+ud(+1) ) ));


mcn=(-u + theta*(1/rss_noa)*rn +(1-theta)*wn );

ggn= (1/tau)*uf +yn;

end;


initval;

//sh=0;
p = 0; 
pai = 0;
u = 0;
ud= 0;
uc= 0;
uh= 0;
um= 0;


i=0;
lamda =0;
iv=0;


v=0;



y =0 ;
k = 0;
h = 0;
iv=0;
c = 0;
m = 0;
w =0 ;
r = 0;

//q=0;
//eue=0;

yn =0 ;
kn = 0;
hn = 0;
cn = 0;
//mn = 0;
wn =0 ;
rn = 0;
//rdn = 0;

pn = 0; 
pain = 0;

in=0;
ivn=0; 
lamdan=0;
//qn=0;


hg=0;
yg=0;

end;
//steady;

steady_state_model;
p = 0; 
pai = 0;
u = 0;
ud= 0;
uc= 0;
uh= 0;
um= 0;


i=0;
lamda =0;
//tiv=0;

v=0;

y =0 ;
k = 0;
h = 0;
iv=0;
c = 0;
m = 0;
w =0 ;
r = 0;

//q=0;
//eue=0;

yn =0 ;
kn = 0;
hn = 0;
cn = 0;
//mn = 0;
wn =0 ;
rn = 0;

//pfn =0;
pn = 0; 
pain = 0;

in=0;
ivn=0; 
lamdan=0;
//qn=0;


hg=0;
yg=0;
end;
@#endif


 shocks;


 var me;  // measurement errors  for 'mc'
 stderr me_std; 

 var mee;  // measurement errors  for 'mc'
 stderr mee_std;

 var meee;  // measurement errors for 'fpai'
 stderr meee_std;




//***********************************//
//**** Start of fig==0 Section **////
//***********************************//


@#if fig==0
@#if data_techzero==0  
 var eu;
 stderr aa0(j,1); 
 
 var ei;
 stderr aa0(j,2);

 var euc;
 stderr aa0(j,3);

  var euh;
 stderr aa0(j,4);

  var ef;
 stderr aa0(j,5);
@#endif

@#if data_techzero==1  
 var eu;
stderr aa0(j,1); 
//stderr 0; 
 
 var ei;
@#if var_shock==0
stderr aa0(j,2);
@#endif
@#if var_shock==1
stderr 0; 
@#endif
 
var euc;
@#if var_shock==0
stderr aa0(j,3);
@#endif
@#if var_shock==1
stderr 0; 
@#endif 

var euh;
@#if var_shock==0
stderr aa0(j,4);
@#endif
@#if var_shock==1
stderr 0; 
@#endif 

var ef;
@#if var_shock==0
stderr aa0(j,5);
@#endif
@#if var_shock==1
stderr 0; 
@#endif 

@#endif


///////////////////
// ELB news shocks//
//////////////////
@#if ELB==2 

 var v1;
 stderr 0.00;
 var v2;
 stderr 0.0;
var v3;
 stderr 0.0;
var v4;
 stderr 0.0;
var v5;
 stderr 0.0;

 var v6;
 stderr 0.00;
 var v7;
 stderr 0.0;
var v8;
 stderr 0.0;
var v9;
 stderr 0.0;
var v10;
 stderr 0.0;

@#endif 
   

///////////////////
// NEWS SHOCKS//
//////////////////
@#if data_techzero==0 


  var eue1;
 stderr 0;

  var eue2;
 stderr 0;

  var eue3;
 stderr 0;

  var eue4;
 stderr aa0(j,6);

  var eue5;
 stderr 0;

  var eue6;
 stderr 0;

  var eue7;
 stderr 0;

 var eue8;
 stderr aa0(j,7);

  var eue9;
 stderr 0;


@#if eshock==16 
  var eue10;
 stderr 0;
  
 var eue11;
 stderr 0;

  var eue12;
 stderr aa0(j,8);

 var eue13;
 stderr 0;
 
 var eue14;
 stderr 0;

 var eue15;
 stderr 0;
 
 var eue;
 stderr aa0(j,9);



@#endif

   
@#endif

@#if data_techzero==1 

   var eue1;
 stderr 0;

  var eue2;
 stderr 0;

  var eue3;
 stderr 0;

  var eue4;
 stderr aa0(j,6);

  var eue5;
 stderr 0;

  var eue6;
 stderr 0;

  var eue7;
 stderr 0;

 var eue8;
 stderr aa0(j,7);

  var eue9;
 stderr 0;


@#if eshock==16
 var eue10;
 stderr aa0(j,0);
  
 var eue11;
 stderr aa0(j,0);

  var eue12;
 stderr aa0(j,8);

 var eue13;
 stderr 0;
 
 var eue14;
 stderr 0;

 var eue15;
 stderr 0;
 
 var eue;
 stderr aa0(j,9);




@#endif

 

@#endif

  
@#endif

//@#endif
//***********************************//
//** End of fig==0 section **//
//***********************************//


//***********************************//
//** Start fig==1 section **//
//***********************************//
@#if fig==1

@#if std_spec==0

@#if data_techzero==0  
 @#if shku==1
 var eu;
 stderr 0.01; 
 @#endif
 @#if shku==0
 var eu;
 stderr 0; 
 @#endif

 @#if shki==1
 var ei;
 stderr 0.01;
 @#endif
 @#if shki==0
 var ei;
 stderr 0;
 @#endif

 @#if shkuc==1
 var euc;
 stderr 0.01;
 @#endif
 @#if shkuc==0
 var euc;
 stderr 0;
 @#endif

 @#if shkuh==1
 var euh;
 stderr 0.01;
 @#endif
 @#if shkuh==0
 var euh;
 stderr 0;
 @#endif 

 @#if shkf==1
 var ef;
 stderr 0.01;
 @#endif
 @#if shkf==0
 var ef;
 stderr 0;
 @#endif 


@#endif

@#if data_techzero==1  
 @#if shku==1
 var eu;
 stderr 0.01; 
 @#endif
 @#if shku==0
 var eu;
 stderr 0; 
 @#endif

 @#if shki==1
 var ei;
 stderr 0.01;
 @#endif
 @#if shki==0
 var ei;
 stderr 0;
 @#endif

 @#if shkuc==1
 var euc;
 stderr 0.01;
 @#endif
 @#if shkuc==0
 var euc;
 stderr 0;
 @#endif

 @#if shkuh==1
 var euh;
 stderr 0.01;
 @#endif
 @#if shkuh==0
 var euh;
 stderr 0;
 @#endif 

 @#if shkf==1
 var ef;
 stderr 0.01;
 @#endif
 @#if shkf==0
 var ef;
 stderr 0;
 @#endif 

@#endif

///////////////////
// ELB news shocks//
//////////////////
@#if ELB==2 

 var v1;
 stderr 0.0;
 var v2;
 stderr 0;
var v3;
 stderr 0.00;
var v4;
 stderr 0.0;
var v5;
 stderr 0.0;
 var v6;
 stderr 0.0;
 var v7;
 stderr 0;
var v8;
 stderr 0.00;
var v9;
 stderr 0.0;
var v10;
 stderr 0.0;

@#endif 

///////////////////
// NEWS SHOCKS//
//////////////////
 @#if shkue1==1
  var eue1;
 stderr 0.01;
 @#endif
  @#if shkue1==0
  var eue1=0;
 @#endif
 
 @#if shkue2==1
  var eue2;
 stderr 0.01;
 @#endif
 @#if shkue2==0
  var eue2=0;
 @#endif
 
 @#if shkue3==1
  var eue3;
 stderr 0.01;
 @#endif
 @#if shkue3==0
  var eue3=0;
 @#endif

 @#if shkue4==1
  var eue4;
 stderr 0.01;
 @#endif
  @#if shkue4==0
  var eue4=0;
 @#endif

@#if shkue5==1
  var eue5;
 stderr 0.01;
 @#endif
 
@#if shkue5==0
  var eue5=0;
 @#endif

@#if shkue6==1
  var eue6;
 stderr 0.01;
 @#endif
 
 @#if shkue6==0
  var eue6=0;
 @#endif

@#if shkue7==1
  var eue7;
 stderr 0.01;
 @#endif
 
 @#if shkue7==0
  var eue7=0;
 @#endif

@#if shkue8==1
  var eue8;
 stderr 0.01;
 @#endif
 
 @#if shkue8==0
  var eue8=0;
 @#endif

@#if shkue9==1
  var eue9;
 stderr 0.01;
 @#endif
 
 @#if shkue9==0
  var eue9=0;
 @#endif

 
 @#if shkue10==1
  var eue10;
  stderr 0.01;
  @#endif
 
  @#if shkue10==0
  var eue10=0;
  @#endif
  
  @#if shkue11==1
  var eue11;
  stderr 0.01;
  @#endif
 
  @#if shkue11==0
  var eue11=0;
  @#endif
   
  @#if shkue12==1
  var eue12;
  stderr 0.01;
  @#endif
 
  @#if shkue12==0
  var eue12=0;
  @#endif

  @#if shkue13==1
  var eue13;
  stderr 0.01;
  @#endif
 
  @#if shkue13==0
  var eue13=0;
  @#endif
  

  @#if shkue14==1
  var eue14;
  stderr 0.01;
  @#endif
 
  @#if shkue14==0
  var eue14=0;
  @#endif

  @#if shkue15==1
  var eue15;
  stderr 0.01;
  @#endif
 
  @#if shkue15==0
  var eue15=0;
  @#endif

   @#if shkue==1
  var eue;
  stderr 0.01;
  @#endif
 
  @#if shkue==0
  var eue=0;
  @#endif



  
 //@#endif

@#endif



@#if std_spec==1

@#if data_techzero==0  
 @#if shku==1
 var eu;
 stderr aa0(j,1); 
 @#endif
 @#if shku==0
 var eu;
 stderr 0; 
 @#endif

 @#if shki==1
 var ei;
 stderr aa0(j,2);
 @#endif
 @#if shki==0
 var ei;
 stderr 0;
 @#endif

 @#if shkuc==1
 var euc;
 stderr aa0(j,3);
 @#endif
 @#if shkuc==0
 var euc;
 stderr 0;
 @#endif

 @#if shkuh==1
 var euh;
 stderr aa0(j,4);
 @#endif
 @#if shkuh==0
 var euh;
 stderr 0;
 @#endif 

  @#if shkf==1
 var ef;
 stderr aa0(j,5);
 @#endif
 @#if shkf==0
 var ef;
 stderr 0;
 @#endif 

@#endif

@#if data_techzero==1  
 @#if shku==1
 var eu;
 stderr aa0(j,1); 
 @#endif
 @#if shku==0
 var eu;
 stderr 0; 
 @#endif

 @#if shki==1
 var ei;
 stderr aa0(j,2);
 @#endif
 @#if shki==0
 var ei;
 stderr 0;
 @#endif

 @#if shkuc==1
 var euc;
 stderr aa0(j,3);
 @#endif
 @#if shkuc==0
 var euc;
 stderr 0;
 @#endif

 @#if shkuh==1
 var euh;
 stderr aa0(j,4);
 @#endif
 @#if shkuh==0
 var euh;
 stderr 0;
 @#endif
 
 @#if shkf==1
 var ef;
 stderr aa0(j,5);
 @#endif
 @#if shkf==0
 var ef;
 stderr 0;
 @#endif
 
@#endif

///////////////////
// ELB news shocks//
//////////////////
@#if ELB==2 

 var v1;
 stderr 0;
 var v2;
 stderr 0;
var v3;
 stderr 0;
var v4;
 stderr 0;
var v5;
 stderr 0.0;
var v6;
 stderr 0;
 var v7;
 stderr 0;
var v8;
 stderr 0;
var v9;
 stderr 0;
var v10;
 stderr 0.0;

@#endif 

///////////////////
// NEWS SHOCKS//
//////////////////
 @#if shkue1==1
  var eue1;
 stderr 0;
 @#endif
  @#if shkue1==0
  var eue1=0;
 @#endif
 
 @#if shkue2==1
  var eue2;
 stderr 0;
 @#endif
 @#if shkue2==0
  var eue2=0;
 @#endif
 
 @#if shkue3==1
  var eue3;
 stderr 0;
 @#endif
 @#if shkue3==0
  var eue3=0;
 @#endif

 @#if shkue4==1
  var eue4;
 stderr aa0(j,6);
 @#endif
  @#if shkue4==0
  var eue4=0;
 @#endif

@#if shkue5==1
  var eue5;
 stderr 0;
 @#endif
 
@#if shkue5==0
  var eue5=0;
 @#endif

@#if shkue6==1
  var eue6;
 stderr 0;
 @#endif
 
 @#if shkue6==0
  var eue6=0;
 @#endif

@#if shkue7==1
  var eue7;
 stderr 0;
 @#endif
 
 @#if shkue7==0
  var eue7=0;
 @#endif


@#if shkue8==1
  var eue8;
 stderr aa0(j,7);
 @#endif
 
 @#if shkue8==0
  var eue8=0;
 @#endif


@#if shkue9==1
  var eue9;
 stderr 0;
 @#endif
 
 @#if shkue9==0
  var eue9=0;
 @#endif



@#if eshock==16
  @#if shkue10==1
  var eue10;
  stderr 0;
  @#endif
 
  @#if shkue10==0
  var eue10=0;
  @#endif
  
  @#if shkue11==1
  var eue11;
  stderr 0;
  @#endif
 
  @#if shkue11==0
  var eue11=0;
  @#endif

   @#if shkue12==1
  var eue12;
  stderr aa0(j,8);
  @#endif
 
  @#if shkue12==0
  var eue12=0;
  @#endif

  @#if shkue13==1
  var eue13;
  stderr 0;
  @#endif
 
  @#if shkue13==0
  var eue13=0;
  @#endif 
  
  @#if shkue14==1
  var eue14;
  stderr 0;
  @#endif
 
  @#if shkue14==0
  var eue14=0;
  @#endif

  @#if shkue15==1
  var eue15;
  stderr 0;
  @#endif
 
  @#if shkue15==0
  var eue15=0;
  @#endif 
 
  @#if shkue==1
  var eue;
  stderr aa0(j,9);
  @#endif
 
  @#if shkue==0
  var eue=0;
  @#endif


`@#endif


@#endif

@#endif




@#if cndvar==1

@#if data_techzero==0  
 var eu;
 stderr aa0(j,1); 
 
 var ei;
 stderr aa0(j,2);

 var euc;
 stderr aa0(j,3);

  var euh;
 stderr aa0(j,4);
@#endif

@#if data_techzero==1  
 var eu;
 stderr aa0(j,1); 
 
 var ei;
 stderr aa0(j,2);

 var euc;
 stderr aa0(j,3);

  var euh;
 stderr aa0(j,4);

 var ef;
 stderr aa0(j,5);
@#endif
   
///////////////////
// ELB news shocks//
//////////////////
@#if ELB==2 

 var v1;
 stderr -0.00;
 var v2;
 stderr -0.00;
var v3;
 stderr -0.00;
var v4;
 stderr -0.00;
var v5;
 stderr -0.00;
var v6;
 stderr -0.00;
 var v7;
 stderr -0.00;
var 8;
 stderr -0.00;
var v9;
 stderr -0.00;
var v10;
 stderr -0.00;

@#endif 
///////////////////
// NEWS SHOCKS//
//////////////////
@#if data_techzero==0 

  var eue1;
 stderr 0;

  var eue2;
 stderr 0;

  var eue3;
 stderr 0;

  var eue4;
 stderr aa0(j,6);

  var eue5;
 stderr 0;

  var eue6;
 stderr 0;

  var eue7;
 stderr0;

 var eue8;
 stderr aa0(j,7);

  var eue9;
 stderr 0;
 



@#if eshock==16
 var eue10;
 stderr 0;
  
 var eue11;
 stderr 0;

  var eue12;
 stderr aa0(j,8);

 var eue13;
 stderr 0;

  var eue14;
 stderr 0;

 var eue15;
 stderr 0;
 
 var eue;
 stderr aa0(j,9);


@#endif


@#endif

@#if data_techzero==1 
 var eue1;
 stderr 0;

  var eue2;
 stderr 0;

  var eue3;
 stderr 0;

  var eue4;
 stderr aa0(j,6);

  var eue5;
 stderr 0;

  var eue6;
 stderr 0;

  var eue7;
 stderr0;

 var eue8;
 stderr aa0(j,7);

  var eue9;
 stderr 0;

@#if eshock==16
  var eue10;
 stderr 0;
  
 var eue11;
 stderr 0;

  var eue12;
 stderr aa0(j,8);

 var eue13;
 stderr 0;

  var eue14;
 stderr 0;

 var eue15;
 stderr 0;
 
 var eue;
 stderr aa0(j,9);

@#endif


@#endif

@#endif


@#endif
//@#endif
//@#endif

//***********************************//
//** End of fig==1 section **//
//***********************************//
 

 
end;


for ii=iia:iib
set_dynare_seed(ii);

@#if large_sample==0

@#if tech==1
 @#if fig==0
    stoch_simul(irf=20, order=2,periods=2000,nograph, noprint,qz_criterium=0.999999 , drop=300)  y a u c iv tiv k h rd pai fpai p tq mc nf pf pf_exp w r rr i tfp tfpu   an cn ivn tivn kn hn rdn pain  mcn nfn sp  pf stk y_g  c_g  tiv_g  iv_g h_g  w_g, tfp_g;    
 @#endif

 @#if fig==1
 @#if cndvar==0
  @#if full_fig==0 
  stoch_simul(irf=50, order=1,periods=2000, noprint,qz_criterium=0.999999,nograph, drop=300) y a u c iv tiv k h rd pai fpai p  tq mc nf pf_exp w r rr i tfp tfpu  an cn ivn tivn kn hn rdn pain  mcn nfn sp   pf stk y_g  c_g  tiv_g iv_g  h_g  w_g tfp_g;  
  @#endif
  @#if full_fig==1 
  stoch_simul(irf=20, order=1,periods=50, qz_criterium=0.999999,nograph,drop=10) y a u c iv tiv k h rd pai fpai p  tq mc nf  pf pf_exp w r rr i tfp tfpu   an cn ivn tivn kn hn rdn pain  mcn nfn sp   pf stk y_g  c_g  tiv_g iv_g  h_g  w_g tfp_g;  
  @#endif 
 @#endif 
 @#if cndvar==1
 stoch_simul(irf=20, order=1,periods=0, noprint,nograph,qz_criterium=0.999999, drop=10,conditional_variance_decomposition = [ 8 12 16 20 40]) y a u c iv tiv k h rd pai fpai p  tq mc nf   pf pf_exp w r rr i tfp tfpu   an cn ivn tivn kn hn rdn pain  mcn nfn sp   pf stk y_g  c_g  tiv_g iv_g  h_g  w_g tfp_g;  
 //**The above is for varaince decomposition: the conditional variance requires theoretical moment, that is periods==0******//
 @#endif
@#endif
@#endif

@#if tech==0
@#if fig==0
    stoch_simul(irf=20, order=1,periods=3000, noprint,nograph,qz_criterium=0.999999,noprint , drop=10)  y yn u mc c iv  k  h  pai fpai p  w r rr i tfp tfpu  tq  cn ivn kn hn pain tqn mcn sp  conf   stk y_g  c_g  h_g iv_g  w_g tfp_g; 
@#endif  
 
@#if fig==1
 @#if cndvar==0
  @#if full_fig==0 
  stoch_simul(irf=50, order=1,periods=2000, noprint,qz_criterium=0.999999,nograph, drop=300) i y yn u mc c iv  k  h  pai fpai p  w r rr  tfp tfpu  tq  cn ivn kn hn pain tqn mcn sp  stk; 
  @#endif
  @#if full_fig==1  
  stoch_simul(irf=50, order=1,periods=50, noprint,qz_criterium=0.999999, drop=10)  y yn u mc c iv  k  h  pai fpai p  w r rr i tfp tfpu  tq  cn ivn kn hn pain tqn mcn sp  conf stk; 
  @#endif
 @#endif
 @#if cndvar==1
 stoch_simul(irf=20, order=1,periods=0, noprint,nograph,qz_criterium=0.999999, drop=10,conditional_variance_decomposition = [1 4 8 12 16 20 40])  y yn u mc c iv  k  h  pai fpai p  w r rr i tfp tfpu  tq cn ivn kn hn pain tqn mcn  sp  conf  stk; 
 @#endif
 @#endif   
@#endif

@#endif

//end
//end

temps = repmat(oo_.dr.ys,1,M_.maximum_lag); %oo_.dr.ys: ss values in declaration orders 

shock_matrix = zeros(options_.irf,M_.exo_nbr); %create shock matrix with number of time periods in colums

@#if ELB==2

s1_dr=oo_.dr.inv_order_var(1); % DR-order of i (Interest rate)
i_dr=oo_.dr.inv_order_var(2); % DR-order of i (Interest rate)
y_dr=oo_.dr.inv_order_var(3); %DR-order of y (output)


shock_matrix(1,strmatch('eu',M_.exo_names,'exact')) =0.01; %value of tfp shock
shock_matrix(1,strmatch('euc',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('euh',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('ef',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('eue1',M_.exo_names,'exact')) = 0; 
shock_matrix(1,strmatch('eue2',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue3',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue4',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue5',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue6',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue7',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue8',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue9',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue10',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue11',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue12',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue13',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue14',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue15',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('me',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('mee',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('meee',M_.exo_names,'exact')) =0;


//// calculating IR of i to TFP shock///
//IRF without ELB//
i_res1_=oo_.irfs.i_eu(1) ;% shows irf of i at t=1
i_res2_=oo_.irfs.i_eu(2) ;% shows irf of i at t=2
i_res3_=oo_.irfs.i_eu(3);
i_res4_=oo_.irfs.i_eu(4);
i_res5_=oo_.irfs.i_eu(5);
i_res6_=oo_.irfs.i_eu(6);

// Just for chechink  
//ei_mk_ = - i_res1/oo_.dr.ghu(i_dr,6);  % shock of ei to offset & make ELB: "6" is the order # of ei shock (interest rate shock) 
//v1_mk_ = - i_res2/oo_.dr.ghu(i_dr,1);  % shock of ei to offset & make ELB: "1" is the order # of v1 shock (interest rate shock) 
//v2_mk_ = - i_res3/oo_.dr.ghu(i_dr,2);
//v3_mk_ = - i_res4/oo_.dr.ghu(i_dr,3);
//v4_mk_ = - i_res5/oo_.dr.ghu(i_dr,4);
//v5_mk_ = - i_res6/oo_.dr.ghu(i_dr,5);




@#endif 

@#if ELB==0
shock_matrix(2,strmatch('v1',M_.exo_names,'exact')) =0;
shock_matrix(3,strmatch('v2',M_.exo_names,'exact')) =0;
shock_matrix(4,strmatch('v3',M_.exo_names,'exact')) =0;
shock_matrix(5,strmatch('v4',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('v5',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('ei',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('eu',M_.exo_names,'exact')) =0.01;
shock_matrix(1,strmatch('euc',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('euh',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('ef',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('eue1',M_.exo_names,'exact')) = 0; 
shock_matrix(1,strmatch('eue2',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue3',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue4',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue5',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue6',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue7',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue8',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue9',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue10',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue11',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue12',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue13',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue14',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue15',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('me',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('mee',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('meee',M_.exo_names,'exact')) =0;

@#endif 

@#if ELB==1
shock_matrix(1,strmatch('ei',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('eu',M_.exo_names,'exact')) =0.01;
shock_matrix(1,strmatch('euc',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('euh',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('ef',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('eue1',M_.exo_names,'exact')) = 0; 
shock_matrix(1,strmatch('eue2',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue3',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue4',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue5',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue6',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue7',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue8',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue9',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue10',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue11',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue12',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue13',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue14',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue15',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('eue',M_.exo_names,'exact')) = 0;
shock_matrix(1,strmatch('me',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('mee',M_.exo_names,'exact')) =0;
shock_matrix(1,strmatch('meee',M_.exo_names,'exact')) =0;

@#endif 


y2 = simult_(temps,oo_.dr,shock_matrix,1);
//y_IRF = y2(:,M_.maximum_lag+1:end)-repmat(oo_.dr.ys,1,options_.irf); %deviation from steady state
y_IRF = y2(:,M_.maximum_lag+1:end); %deviation from steady state

simseries_irf_y{j,1}=y_IRF(strmatch('y',M_.endo_names,'exact'),:);
simseries_irf_h{j,1}=y_IRF(strmatch('h',M_.endo_names,'exact'),:);
simseries_irf_a{j,1}=y_IRF(strmatch('a',M_.endo_names,'exact'),:);
simseries_irf_c{j,1}=y_IRF(strmatch('c',M_.endo_names,'exact'),:);
simseries_irf_tiv{j,1}=y_IRF(strmatch('tiv',M_.endo_names,'exact'),:);
simseries_irf_iv{j,1}=y_IRF(strmatch('iv',M_.endo_names,'exact'),:);
simseries_irf_pai{j,1}=y_IRF(strmatch('pai',M_.endo_names,'exact'),:);
simseries_irf_tfp{j,1}=y_IRF(strmatch('tfp',M_.endo_names,'exact'),:);
simseries_irf_tfpu{j,1}=y_IRF(strmatch('tfpu',M_.endo_names,'exact'),:);
simseries_irf_tq{j,1}=y_IRF(strmatch('tq',M_.endo_names,'exact'),:);
simseries_irf_sp{j,1}=y_IRF(strmatch('sp',M_.endo_names,'exact'),:);
simseries_irf_conf{j,1}=y_IRF(strmatch('conf',M_.endo_names,'exact'),:);
simseries_irf_i{j,1}=y_IRF(strmatch('i',M_.endo_names,'exact'),:);

simseries_irf_yg{j,1}=y_IRF(strmatch('yg',M_.endo_names,'exact'),:);

simseries_irf_w{j,1}=y_IRF(strmatch('w',M_.endo_names,'exact'),:);
simseries_irf_mc{j,1}=y_IRF(strmatch('mc',M_.endo_names,'exact'),:);
simseries_irf_r{j,1}=y_IRF(strmatch('r',M_.endo_names,'exact'),:);
simseries_irf_rr{j,1}=y_IRF(strmatch('rr',M_.endo_names,'exact'),:);

simseries_irf_pf{j,1}=y_IRF(strmatch('pf',M_.endo_names,'exact'),:);
simseries_irf_pf_exp{j,1}=y_IRF(strmatch('pf_exp',M_.endo_names,'exact'),:);
simseries_irf_rd{j,1}=y_IRF(strmatch('rd',M_.endo_names,'exact'),:);
simseries_irf_nf{j,1}=y_IRF(strmatch('nf',M_.endo_names,'exact'),:);

irf_y_=cell2mat(simseries_irf_y);
irf_a_=cell2mat(simseries_irf_a);
irf_c_=cell2mat(simseries_irf_c);
irf_tiv_=cell2mat(simseries_irf_tiv);
irf_iv_=cell2mat(simseries_irf_iv);
irf_pai_=cell2mat(simseries_irf_pai);
irf_tfp_=cell2mat(simseries_irf_tfp);
irf_tfpu_=cell2mat(simseries_irf_tfpu);
irf_h_=cell2mat(simseries_irf_h);
irf_tq_=cell2mat(simseries_irf_tq);
irf_sp_=cell2mat(simseries_irf_sp);
irf_conf_=cell2mat(simseries_irf_conf);
irf_i_=cell2mat(simseries_irf_i);
irf_mc_=cell2mat(simseries_irf_mc);
irf_w_=cell2mat(simseries_irf_w);
irf_r_=cell2mat(simseries_irf_r);
irf_rr_=cell2mat(simseries_irf_rr);
irf_yg_=cell2mat(simseries_irf_yg);
irf_mc_=cell2mat(simseries_irf_mc);
irf_pf_=cell2mat(simseries_irf_pf);
irf_rd_=cell2mat(simseries_irf_rd);


@#if ELB==2
//IRF with ELB //
i_res1=irf_i(1) ;% shows irf of i at t=1
i_res2=irf_i(2) ;% shows irf of i at t=2
i_res3=irf_i(3) ;
i_res4=irf_i(4) ;
i_res5=irf_i(5) ;
i_res6=irf_i(6) ;
i_res7=irf_i(7) ;
i_res8=irf_i(8) ;
i_res9=irf_i(9) ;
i_res10=irf_i(10) ;
i_res11=irf_i(11) ;
i_res12=irf_i(12) ;
i_res13=irf_i(13) ;
i_res14=irf_i(14) ;
i_res15=irf_i(15) ;
i_res16=irf_i(16) ;
i_res17=irf_i(17) ;
i_res18=irf_i(18) ;
i_res19=irf_i(19) ;
i_res20=irf_i(20) ;

//Displaying IR of i to TFP shock
IR_of_i =[' IFR of Interest rate to a tfp shock  ']
format short
IR_i =[i_res1 i_res2 i_res3 i_res4 i_res5 i_res6 i_res7 i_res8 i_res9 i_res10
       i_res11 i_res12 i_res13 i_res14 i_res15 i_res16 i_res17 i_res18 i_res19 i_res20 
]

format rational
IR_i =[i_res1 i_res2 i_res3 i_res4 i_res5 i_res6 i_res7 i_res8 i_res9 i_res10 ]
IR_i2 =[ i_res11 i_res12 i_res13 i_res14 i_res15 i_res16 i_res17 i_res18 i_res19 i_res20 ]

@#endif

end
end

@#if bayirf==1

@#if conf_band==0
irf_y_lb=prctile(irf_y_,5);
irf_a_lb=prctile(irf_a_,5);
irf_c_lb=prctile(irf_c_,5);
irf_tiv_lb=prctile(irf_tiv_,5);
irf_iv_lb=prctile(irf_iv_,5);
irf_pai_lb=prctile(irf_pai_,5);
irf_tfp_lb=prctile(irf_tfp_,5);
irf_i_lb=prctile(irf_i_,5);
irf_mc_lb=prctile(irf_mc_,5);
irf_w_lb=prctile(irf_w_,5);
irf_r_lb=prctile(irf_r_,5);
irf_rr_lb=prctile(irf_rr_,5);
irf_yg_lb=prctile(irf_yg_,5);
irf_pf_lb=prctile(irf_pf_,5);
irf_rd_lb=prctile(irf_rd_,5);
irf_h_lb=prctile(irf_h_,5);
irf_tfpu_lb=prctile(irf_tfpu_,5);


irf_y_hb=prctile(irf_y_,95);
irf_a_hb=prctile(irf_a_,95);
irf_c_hb=prctile(irf_c_,95);
irf_tiv_hb=prctile(irf_tiv_,95);
irf_iv_hb=prctile(irf_iv_,95);
irf_pai_hb=prctile(irf_pai_,95);
irf_tfp_hb=prctile(irf_tfp_,95);
irf_i_hb=prctile(irf_i_,95);
irf_mc_hb=prctile(irf_mc_,95);
irf_w_hb=prctile(irf_w_,95);
irf_r_hb=prctile(irf_r_,95);
irf_rr_hb=prctile(irf_rr_,95);
irf_yg_hb=prctile(irf_yg_,95);
irf_pf_hb=prctile(irf_pf_,95);
irf_rd_hb=prctile(irf_rd_,95);
irf_h_hb=prctile(irf_h_,95);
irf_tfpu_hb=prctile(irf_tfpu_,95);
@#endif

@#if conf_band==1
irf_y_lb=prctile(irf_y_,2.5);
irf_a_lb=prctile(irf_a_,2.5);
irf_c_lb=prctile(irf_c_,2.5);
irf_tiv_lb=prctile(irf_tiv_,2.5);
irf_iv_lb=prctile(irf_iv_,2.5);
irf_pai_lb=prctile(irf_pai_,2.5);
irf_tfp_lb=prctile(irf_tfp_,2.5);
irf_i_lb=prctile(irf_i_,2.5);
irf_mc_lb=prctile(irf_mc_,2.5);
irf_w_lb=prctile(irf_w_,2.5);
irf_r_lb=prctile(irf_r_,2.5);
irf_rr_lb=prctile(irf_rr_,2.5);
irf_yg_lb=prctile(irf_yg_,2.5);
irf_pf_lb=prctile(irf_pf_,2.5);
irf_rd_lb=prctile(irf_rd_,2.5);
irf_h_lb=prctile(irf_h_,2.5);
irf_tfpu_lb=prctile(irf_tfpu_,2.5);


irf_y_hb=prctile(irf_y_,97.5);
irf_a_hb=prctile(irf_a_,97.5);
irf_c_hb=prctile(irf_c_,97.5);
irf_tiv_hb=prctile(irf_tiv_,97.5);
irf_iv_hb=prctile(irf_iv_,97.5);
irf_pai_hb=prctile(irf_pai_,97.5);
irf_tfp_hb=prctile(irf_tfp_,97.5);
irf_i_hb=prctile(irf_i_,97.5);
irf_mc_hb=prctile(irf_mc_,97.5);
irf_w_hb=prctile(irf_w_,97.5);
irf_r_hb=prctile(irf_r_,97.5);
irf_rr_hb=prctile(irf_rr_,97.5);
irf_yg_hb=prctile(irf_yg_,97.5);
irf_pf_hb=prctile(irf_pf_,97.5);
irf_rd_hb=prctile(irf_rd_,97.5);
irf_h_hb=prctile(irf_h_,97.5);
irf_tfpu_hb=prctile(irf_tfpu_,97.5);
@#endif




@#if conf_band==2
irf_y_lb=prctile(irf_y_,16);
irf_a_lb=prctile(irf_a_,16);
irf_c_lb=prctile(irf_c_,16);
irf_tiv_lb=prctile(irf_tiv_,16);
irf_iv_lb=prctile(irf_iv_,16);
irf_pai_lb=prctile(irf_pai_,16);
irf_tfp_lb=prctile(irf_tfp_,16);
irf_i_lb=prctile(irf_i_,16);
irf_mc_lb=prctile(irf_mc_,16);
irf_w_lb=prctile(irf_w_,16);
irf_r_lb=prctile(irf_r_,16);
irf_rr_lb=prctile(irf_rr_,16);
irf_yg_lb=prctile(irf_yg_,16);
irf_pf_lb=prctile(irf_pf_,16);
irf_rd_lb=prctile(irf_rd_,16);
irf_h_lb=prctile(irf_h_,16);
irf_tfpu_lb=prctile(irf_tfpu_,16);


irf_y_hb=prctile(irf_y_,83);
irf_a_hb=prctile(irf_a_,83);
irf_c_hb=prctile(irf_c_,83);
irf_tiv_hb=prctile(irf_tiv_,83);
irf_iv_hb=prctile(irf_iv_,83);
irf_pai_hb=prctile(irf_pai_,83);
irf_tfp_hb=prctile(irf_tfp_,83);
irf_i_hb=prctile(irf_i_,83);
irf_mc_hb=prctile(irf_mc_,83);
irf_w_hb=prctile(irf_w_,83);
irf_r_hb=prctile(irf_r_,83);
irf_rr_hb=prctile(irf_rr_,83);
irf_yg_hb=prctile(irf_yg_,83);
irf_pf_hb=prctile(irf_pf_,83);
irf_rd_hb=prctile(irf_rd_,83);
irf_h_hb=prctile(irf_h_,83);
irf_tfpu_hb=prctile(irf_tfpu_,83);
@#endif



@#endif

@#if bayirf==0
irf_y=irf_y_;
irf_a=irf_a_;
irf_c=irf_c_;
irf_tiv=irf_tiv_;
irf_iv=irf_iv_;
irf_pai=irf_pai_;
irf_tfp=irf_tfp_;
irf_i=irf_i_;
irf_mc=irf_mc_;
irf_w=irf_w_;
irf_r=irf_r_;
irf_rr=irf_rr_;
irf_yg=irf_yg_;
irf_pf=irf_pf_;
irf_rd=irf_rd_;
irf_h=irf_h_;
irf_tfpu=irf_tfpu_;

@#endif



@#if bayirf==1

@#if mean_median==1
irf_y=mean(irf_y_);
irf_a=mean(irf_a_);
irf_c=mean(irf_c_);
irf_tiv=mean(irf_tiv_);
irf_iv=mean(irf_iv_);
irf_pai=mean(irf_pai_);
irf_tfp=mean(irf_tfp_);
irf_i=mean(irf_i_);
irf_mc=mean(irf_mc_);
irf_w=mean(irf_w_);
irf_r=mean(irf_r_);
irf_rr=mean(irf_rr_);
irf_yg=mean(irf_yg_);
irf_pf=mean(irf_pf_);
irf_rd=mean(irf_rd_);
irf_h=mean(irf_h_);
irf_tfpu=mean(irf_tfpu_);
@#endif

@#if mean_median==2
irf_y=median(irf_y_);
irf_a=median(irf_a_);
irf_c=median(irf_c_);
irf_tiv=median(irf_tiv_);
irf_iv=median(irf_iv_);
irf_pai=median(irf_pai_);
irf_tfp=median(irf_tfp_);
irf_i=median(irf_i_);
irf_mc=median(irf_mc_);
irf_w=median(irf_w_);
irf_r=median(irf_r_);
irf_rr=median(irf_rr_);
irf_yg=median(irf_yg_);
irf_pf=median(irf_pf_);
irf_rd=median(irf_rd_);
irf_h=median(irf_h_);
irf_tfpu=median(irf_tfpu_);
@#endif

@#endif

irfc_y=irf_y'; irfc_pai=irf_pai'; irfc_c=irf_c';  irfc_iv=irf_iv'; irfc_tiv=irf_tiv'; irfc_rr=irf_rr';  irfc_r=irf_r';  irfc_w=irf_w';  irfc_mc=irf_mc';  irfc_h=irf_h';  irfc_i=irf_i';  irfc_a=irf_a';  irfc_rd=irf_rd';  irfc_tfpu=irf_tfpu'; 
irfc_y_hb=irf_y_hb'; irfc_pai_hb=irf_pai_hb'; irfc_c_hb=irf_c_hb';  irfc_iv_hb=irf_iv_hb'; irfc_tiv_hb=irf_tiv_hb'; irfc_rr_hb=irf_rr_hb';  irfc_r_hb=irf_r_hb';  irfc_w_hb=irf_w_hb';  irfc_mc_hb=irf_mc_hb';  irfc_h_hb=irf_h_hb';  irfc_i_hb=irf_i_hb';  irfc_a_hb=irf_a_hb';  irfc_rd_hb=irf_rd_hb';  irfc_tfpu_hb=irf_tfpu_hb'; 
irfc_y_lb=irf_y_lb'; irfc_pai_lb=irf_pai_lb'; irfc_c_lb=irf_c_lb';  irfc_iv_lb=irf_iv_lb'; irfc_tiv_lb=irf_tiv_lb'; irfc_rr_lb=irf_rr_lb';  irfc_r_lb=irf_r_lb';  irfc_w_lb=irf_w_lb';  irfc_mc_lb=irf_mc_lb';  irfc_h_lb=irf_h_lb';  irfc_i_lb=irf_i_lb';  irfc_a_lb=irf_a_lb';  irfc_rd_lb=irf_rd_lb';  irfc_tfpu_lb=irf_tfpu_lb'; 




figure(1)
subplot(4,4,1)
if lsp ==1
plot(irf_tfpu,'k-', 'LineWidth', 2);hold on; plot(irf_tfpu_lb,':', 'LineWidth', 2);plot(irf_tfpu_hb,':', 'LineWidth', 2);
//plot(irf_tfpu,'k-');
elseif lsp==2
plot(irf_tfpu,'r-');
elseif lsp==3
plot(irf_tfpu,'b-.');
elseif lsp==4
plot(irf_tfpu,'g--');
elseif lsp==5
plot(irf_tfpu,'k--');
end
hold on
title('u: Exogenous Technology');

subplot(4,4,2)
if lsp ==1
plot(irf_y,'k-', 'LineWidth', 2);hold on; plot(irf_y_lb,':', 'LineWidth', 2);plot(irf_y_hb,':', 'LineWidth', 2);
elseif lsp==2
 //@#if bayirf==1
 plot(irf_y,'r-', 'LineWidth', 2);hold on; plot(irf_y_lb,':', 'LineWidth', 2);plot(irf_y_hb,':', 'LineWidth', 2);
 //@#endif
 //plot(irf_y,'r-');
elseif lsp==3
plot(irf_y,'b-.');
elseif lsp==4
plot(irf_y,'g--');
elseif lsp==5
plot(irf_y,'k--');
end
hold on
title('y: Output');

subplot(4,4,3)
if lsp ==1
plot(irf_pai,'k-', 'LineWidth', 2);hold on; plot(irf_pai_lb,':', 'LineWidth', 2);plot(irf_pai_hb,':', 'LineWidth', 2);
//plot(irf_pai,'k-');
elseif lsp==2
plot(irf_pai,'r-');
elseif lsp==3
plot(irf_pai,'b-.');
elseif lsp==4
plot(irf_pai,'g--');
elseif lsp==5
plot(irf_pai,'k--');
end
hold on
title('pai: Inflation');

subplot(4,4,4)
if lsp ==1
plot(irf_rr,'k-', 'LineWidth', 2);hold on; plot(irf_rr_lb,':', 'LineWidth', 2);plot(irf_rr_hb,':', 'LineWidth', 2);
//plot(irf_rr,'k-');
elseif lsp==2
plot(irf_rr,'r-');
elseif lsp==3
plot(irf_rr,'b-.');
elseif lsp==4
plot(irf_rr,'g--');
elseif lsp==5
plot(irf_rr,'k--');
end
hold on
title('rr: Real Interest Rate');


subplot(4,4,5)
if lsp ==1
plot(irf_w,'k-', 'LineWidth', 2);hold on; plot(irf_w_lb,':', 'LineWidth', 2);plot(irf_w_hb,':', 'LineWidth', 2);
//plot(irf_w,'k-');
elseif lsp==2
plot(irf_w,'r-');
elseif lsp==3
plot(irf_w,'b-.');
elseif lsp==4
plot(irf_w,'g--');
elseif lsp==5
plot(irf_w,'k--');
end
hold on
title('w: Wage');

subplot(4,4,6)
if lsp ==1
plot(irf_h,'k-', 'LineWidth', 2);hold on; plot(irf_h_lb,':', 'LineWidth', 2);plot(irf_h_hb,':', 'LineWidth', 2);
//plot(irf_h,'k-');
elseif lsp==2
plot(irf_h,'r-');
elseif lsp==3
plot(irf_h,'b-.');
elseif lsp==4
plot(irf_h,'g--');
elseif lsp==5
plot(irf_h,'k--');
end
hold on
title('h:Labor');

subplot(4,4,7)
if lsp ==1
plot(irf_mc,'k-', 'LineWidth', 2);hold on; plot(irf_mc_lb,':', 'LineWidth', 2);plot(irf_mc_hb,':', 'LineWidth', 2);
//plot(irf_mc,'k-');
elseif lsp==2
plot(irf_mc,'r-');
elseif lsp==3
plot(irf_mc,'b-.');
elseif lsp==4
plot(irf_mc,'g--');
elseif lsp==5
plot(irf_mc,'k--');
end
hold on
title('mc: Marginal Cost');

subplot(4,4,8)
if lsp ==1
plot(irf_i,'k-', 'LineWidth', 2);hold on; plot(irf_i_lb,':', 'LineWidth', 2);plot(irf_i_hb,':', 'LineWidth', 2);
//plot(irf_i,'k-');
elseif lsp==2
plot(irf_i,'r-');
elseif lsp==3
plot(irf_i,'b-.');
elseif lsp==4
plot(irf_i,'g--');
elseif lsp==5
plot(irf_i,'k--');
end
hold on
title('i: Nominal Interest Rate');

@#if tech==1
subplot(4,4,9)
if lsp ==1
plot(irf_a,'k-', 'LineWidth', 2);hold on; plot(irf_a_lb,':', 'LineWidth', 2);plot(irf_a_hb,':', 'LineWidth', 2);
//plot(irf_a,'k-');
elseif lsp==2
plot(irf_a,'r-');
elseif lsp==3
plot(irf_a,'b-.');
elseif lsp==4
plot(irf_a,'g--');
elseif lsp==5
plot(irf_a,'k--');
end
hold on
title('a: Endogenous Technology');

subplot(4,4,10)
if lsp ==1
plot(irf_rd,'k-', 'LineWidth', 2);hold on; plot(irf_rd_lb,':', 'LineWidth', 2);plot(irf_rd_hb,':', 'LineWidth', 2);
//plot(irf_rd,'k-');
elseif lsp==2
plot(irf_rd,'r-');
elseif lsp==3
plot(irf_rd,'b-.');
elseif lsp==4
plot(irf_rd,'g--');
elseif lsp==5
plot(irf_rd,'k--');
end
hold on
title('rd: Product Development Investment');

@#endif



figure(20)
subplot(4,3,1)
if lsp ==1
plot(irf_tfpu,'k-');
elseif lsp==2
plot(irf_tfpu,'r-');
elseif lsp==3
plot(irf_tfpu,'b-.');
elseif lsp==4
plot(irf_tfpu,'g--');
elseif lsp==5
plot(irf_tfpu,'k--');
end
hold on
title('u: Exogenous Technology');

subplot(4,3,2)
if lsp ==1
plot(irf_y,'k-');
elseif lsp==2
plot(irf_y,'r-');
elseif lsp==3
plot(irf_y,'b-.');
elseif lsp==4
plot(irf_y,'g--');
elseif lsp==5
plot(irf_y,'k--');
end
hold on
title('y: Output');

subplot(4,3,3)
if lsp ==1
plot(irf_pai,'k-');
elseif lsp==2
plot(irf_pai,'r-');
elseif lsp==3
plot(irf_pai,'b-.');
elseif lsp==4
plot(irf_pai,'g--');
elseif lsp==5
plot(irf_pai,'k--');
end
hold on
title('pai: Inflation');

subplot(4,3,4)
if lsp ==1
plot(irf_rr,'k-');
elseif lsp==2
plot(irf_rr,'r-');
elseif lsp==3
plot(irf_rr,'b-.');
elseif lsp==4
plot(irf_rr,'g--');
elseif lsp==5
plot(irf_rr,'k--');
end
hold on
title('rr: Real Interest Rate');

subplot(4,3,5)
if lsp ==1
plot(irf_w,'k-');
elseif lsp==2
plot(irf_w,'r-');
elseif lsp==3
plot(irf_w,'b-.');
elseif lsp==4
plot(irf_w,'g--');
elseif lsp==5
plot(irf_w,'k--');
end
hold on
title('w: Wage');

subplot(4,3,6)
if lsp ==1
plot(irf_h,'k-');
elseif lsp==2
plot(irf_h,'r-');
elseif lsp==3
plot(irf_h,'b-.');
elseif lsp==4
plot(irf_h,'g--');
elseif lsp==5
plot(irf_h,'k--');
end
hold on
title('h:Labor');

subplot(4,3,7)
if lsp ==1
plot(irf_mc,'k-');
elseif lsp==2
plot(irf_mc,'r-');
elseif lsp==3
plot(irf_mc,'b-.');
elseif lsp==4
plot(irf_mc,'g--');
elseif lsp==5
plot(irf_mc,'k--');
end
hold on
title('mc: Marginal Cost');

@#if tech==1
subplot(4,3,8)
if lsp ==1
plot(irf_a,'k-');
elseif lsp==2
plot(irf_a,'r-');
elseif lsp==3
plot(irf_a,'b-.');
elseif lsp==4
plot(irf_a,'g--');
elseif lsp==5
plot(irf_a,'k--');
end
hold on
title('a: Endogenous Technology');

subplot(4,3,9)
if lsp ==1
plot(irf_rd,'k-');
elseif lsp==2
plot(irf_rd,'r-');
elseif lsp==3
plot(irf_rd,'b-.');
elseif lsp==4
plot(irf_rd,'g--');
elseif lsp==5
plot(irf_rd,'k--');
end
hold on
title('rd: Product Development Investment');
@#endif






